Menu

#500 #pragma pack(push,n) does not work when n is a macro

v1.0 (example)
open
nobody
None
5
2015-10-08
2015-10-08
vitaly_s
No

GCC 5.2.0.

pragma pack(push,n) does not work when n is a macro

Example code produces:

sizeof(struct A) = 16
sizeof(struct B) = 12
sizeof(struct C) = 16

while sizeof(struct C) must be 12.

Also, #pragma pack(n) does not work with macro. See example in file b.c.

gcc -O2 -o b.exe b.c

1 Attachments
b.c

Related

Bugs: #500

Discussion

  • Kai Tietz

    Kai Tietz - 2015-10-09

    Thanks for reporting. I tested it with current trunk and older gcc
    (4.9, 4.8), and things look pretty similar. So this isn't actually a
    regression, but it is a missing feature for gcc. So you might want to
    report this missing feature to gcc's bz for discussion.

    Thanks,
    Kai

    2015-10-08 16:45 GMT+02:00 vitaly_s vitalysxii@users.sf.net:


    [bugs:#500] #pragma pack(push,n) does not work when n is a macro

    Status: open
    Group: v1.0 (example)
    Created: Thu Oct 08, 2015 02:45 PM UTC by vitaly_s
    Last Updated: Thu Oct 08, 2015 02:45 PM UTC
    Owner: nobody
    Attachments:

    b.c (843 Bytes; text/plain)

    GCC 5.2.0.

    pragma pack(push,n) does not work when n is a macro

    Example code produces:

    sizeof(struct A) = 16
    sizeof(struct B) = 12
    sizeof(struct C) = 16

    while sizeof(struct C) must be 12.

    Also, #pragma pack(n) does not work with macro. See example in file b.c.

    gcc -O2 -o b.exe b.c


    Sent from sourceforge.net because you indicated interest in
    https://sourceforge.net/p/mingw-w64/bugs/500/

    To unsubscribe from further messages, please visit
    https://sourceforge.net/auth/subscriptions/

     

    Related

    Bugs: #500

    • vitaly_s

      vitaly_s - 2015-10-10

      Thanks for answer. After I have found it, I didn’t test it with previous releases. It is good to have this information now.

      So, to conclude... While my own code can use something like this

      #pragma pack(push)
      
      #if     defined(_WIN64)
      #pragma pack(8)
      #elif   defined(_WIN32)
      #pragma pack(4)
      #else
      #error Win32 and Win64 targets are currently supported
      #endif
      
      ...
      
      #pragma pack(pop)
      

      although it would be better to use simple '#pragma pack(push, _PLATFORM_PACKING)' the bug still has much more consequences. Almost every include file supplied with GCC also has '#pragma pack(push,_CRT_PACKING)' directive. Thus, it is certainly a bug, not a 'missing feature', because GCC itself heavily relies on it.

       

Log in to post a comment.