[lug] More packing troubles...
David Trowbridge
jupiter at flatirons.org
Mon Jun 11 22:02:58 MDT 2001
After digging through some gcc code (ewwww) I figured it out.
the form that works, instead of this:
#pragma pack (push, pre_spi)
#pragma pack (2)
...
#pragma pack (pop, pre_spi)
is this:
#pragma pack (push, pre_spi, 2)
...
#pragma pack (pop)
I'll wait until 3 is out for a little while, then probably file a bug
report. Since #pragma pack(push[, id], <n>) is intended for MS VC(++)
compatibility, I think it would be best if it used the same
syntax/specification!
Thanks for all your comments,
-David
-------------------
David Trowbridge
jupiter at flatirons.org
http://jupiter.babylonia.flatirons.org
"Base 8 is just like base 10 really...if you're missing two fingers"
-Tom Lehrer
On 11 Jun 2001, Tom Tromey wrote:
> >>>>> "David" == David Trowbridge <jupiter at flatirons.org> writes:
>
> David> I just now ran into the same problem with porting a network app and
> David> #pragma pack. My problem is this: in the app, before a network command
> David> structure, there are these two lines:
> David> #pragma pack (push, pre_spi)
> David> #pragma pack (2)
> David> and ending with this after the struct:
> David> #pragma pack (pop, pre_spi)
>
> David> I've defined HAVE_PRAGMA_PACK_PUSH_POP to 1, but I get the
> David> following error
>
> HAVE_PRAGMA_PACK_PUSH_POP is a gcc back-end macro. It is only used when
> building gcc itself. There's no point in defining it in your code.
>
> HAVE_PRAGMA_PACK_PUSH_POP is defined for all Linux targets. So this
> feature should be available in your Linux gcc. You could try
> compiling with `-Wunknown-pragmas' to verify this.
>
> David> and can't find any docs on the exact format gcc wants:
> David> spi.h:35: warning: malformed '#pragma pack(push[,id],<n>)'
> David> spi.h:35: warning: ignoring pragma:
>
> I looked at the manual and I also didn't see anything. Well, there's
> some stuff in tm.texi, that's lame since that document is describing
> the back end and not what users ought to do. Could you submit a gcc
> bug report for this? It is very easy to do:
>
> http://gcc.gnu.org/bugs.html
>
>
> The text in tm.texi, which is part of gcc 3.0, says (I just extract
> the Texinfo):
>
> The pack(push,<n>) pragma specifies the maximum alignment
> (in bytes) of fields within a structure, in much the same way as the
> @samp{__aligned__} and @samp{__packed__} @code{__attribute__}s do. A
> pack value of zero resets the behaviour to the default. Successive
> invocations of this pragma cause the previous values to be stacked, so
> that invocations of @samp{#pragma pack(pop)} will return to the previous
> value.
>
>
> I'd advise not using these pragmas if you possibly can avoid it. I
> imagine (though I'm not positive -- the back end isn't really my area)
> that the resulting code it will be slow.
>
> Tom
> _______________________________________________
> Web Page: http://lug.boulder.co.us
> Mailing List: http://lists.lug.boulder.co.us/mailman/listinfo/lug
>
More information about the LUG
mailing list