From mboxrd@z Thu Jan 1 00:00:00 1970 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: fee84,e1e29162948ee32a X-Google-Attributes: gidfee84,public From: Alan Rotnemer <73765.1577@CompuServe.COM> Subject: Re: isalign option on cxx? Date: 1996/02/28 Message-ID: <4h0d1s$cp3$1@mhade.production.compuserve.com>#1/1 X-Deja-AN: 141470022 references: <4gkea1$5fm@zk2nws.zko.dec.com> organization: Landmark Systems newsgroups: comp.unix.osf.osf1 Tom: Thank you for your reply to my question regarding the "isalign" option. I wonder if you would be familiar with the following problem I recently ran into while porting code from another UNIX platform. The code that I listed below yields different results from the "cc" and "cxx" compilers (no compiler options). It seems that the cxx compiler has a problem with a pointer reference to the unsigned short within a struct when the field is not on an even boundary and the structure is packed. "cc" works OK. Is this a bug in cxx? Thanks again. Alan Rotnemer #include #include #pragma pack 1 struct aa { char cc1[7] ; unsigned short us ; }; struct aa xaa; void main() { struct aa *pxaa, *pxaa1, *pxaa2; pxaa = &xaa; xaa.us = (unsigned short ) 299; printf("size of aa struct is %u\n", sizeof(struct aa)); printf ("dot non-calloc 299 moved to %u\n", xaa.us); printf ("...but using ptr ref its is %u\n", pxaa->us); printf("...hex is ptr: %x, dot: %x \n", pxaa->us, xaa.us); pxaa->us = (unsigned short ) 299; printf ("pointer non-calloc 299 moved to %u\n", pxaa->us); printf ("....but using dot ref it is %u\n", xaa.us); pxaa1 = (struct aa *) calloc(1, sizeof(struct aa)); pxaa1->us = 299; printf ("calloc ptr ref 299 moved to %u\n", pxaa1->us); } #pragma pack 8 *************************************************************************** on cc compiler I get ... size of aa struct is 9 dot non-calloc 299 moved to 299 ..but using ptr ref its is 299 ..hex is ptr: 12b, dot: 12b pointer non-calloc 299 moved to 299 ...but using dot ref it is 299 calloc ptr ref 299 moved to 299 **************************************************************************** on cxx compiler I get.. size of aa struct is 9 dot non-calloc 299 moved to 299 ..but using ptr ref its is 43 ..hex is ptr: 2b, dot: 12b pointer non-calloc 299 moved to 43 ...but using dot ref it is 299 calloc ptr ref 299 moved to 43