Message-Id: <199906082242.RAA19006@mercury.xraylith.wisc.edu> To: Andris Pavenis cc: djgpp-workers AT delorie DOT com, egcs-bugs AT egcs DOT cygnus DOT com Subject: Re: problem with data alignment with egcs-19990602 In-Reply-To: Your message of "Tue, 08 Jun 1999 10:27:08 -0000." <99060810411500 DOT 00968 AT hal> Date: Tue, 08 Jun 1999 17:42:16 -0500 From: Mumit Khan Reply-To: djgpp-workers AT delorie DOT com Andris Pavenis writes: > Problem seems to be related with use of #pragma pack(): > I had to put definition of some structures between > #pragma pack(1) > and > #pragma pack() > > It looks that with gcc 2.95 tree the second line (#pragma pack()) > is ignored and as result I'm getting wrong code. > - using __attribute__(packed) instead fixes the problem > - no changes needed for egcs-1.1.2 (#pragma pack() works > as I expect) > > Below is simple test example that ilustrates the problem > > ---------------------------------------------------- > #include > #include > > > #pragma pack(1) > #pragma pack() > > > class Test1 > { > public: > char a; > long b; > Test1 (void) > { > printf ("%p\n",(((char *) & b)-((char *) & a))); > } > }; > > > int main (void) > { > Test1 x; > return 0; > } > > ---------------------------------------------------- > With gcc-1.1.2 I'm getting output 4 > With gcc-2.95 prerelease I'm getting 1 > > So we should either have a warning from compiler that #pragma pack() > should not be used or this problem must be fixed > The alignment should revert to the default when `#pragma pack()' is encountered (ie., without an token between the '(' and ')'). Does the following fix it? Tue Jun 8 17:31:18 1999 Mumit Khan * c-pragma.c (handle_pragma_token): Handle `#pragma pack()' correctly. Index: c-pragma.c =================================================================== RCS file: /cvs/egcs/egcs/gcc/c-pragma.c,v retrieving revision 1.16 diff -u -3 -p -r1.16 c-pragma.c --- c-pragma.c 1999/04/26 21:18:07 1.16 +++ c-pragma.c 1999/06/08 23:37:49 @@ -383,8 +383,15 @@ handle_pragma_token (string, token) case ps_left: if (token == NULL_TREE) - state = (strcmp (string, ")") ? ps_bad : ps_right); - + { + if (strcmp (string, ")") == 0) + { + align = 0; + state = ps_right; + } + else + state = ps_bad; + } else if (TREE_CODE (token) == INTEGER_CST) goto handle_align; Regards, Mumit