Mail Archives: djgpp-workers/1999/06/08/20:01:33
Andris Pavenis <andris AT stargate DOT astr DOT lu DOT lv> 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 <stdio.h>
> #include <assert.h>
>
>
> #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 <khan AT xraylith DOT wisc DOT edu>
* 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
- Raw text -