Re: padding mechanism in structures



Mehta Shailendrakumar wrote:
>
.... snip ...
>
> The new functionality also allows you to use code, such as header
> files, that uses pack pragmas to set packing alignments that differ
> from the packing value set in your code:
>
> #pragma pack( push, before_include1 )
> #include "include1.h"
> #pragma pack( pop, before_include1 )
>
> In the previous example, your code is protected from any changes
> to the packing value that might occur in include.h.
>
> Name: pack.c
> pack.c Type: Textpad File (application/x-unknown-content-type-cfile)
> Encoding: x-uuencode

Never attach anything to a usenet article, especially a binary.
This is a text only medium.

In addition, pragma is not sanctioned by the standard. From N869:

[#1] A preprocessing directive of the form

# pragma pp-tokens-opt new-line

where the preprocessing token STDC does not immediately
follow pragma in the directive (prior to any macro
replacement)136) causes the implementation to behave in an
implementation-defined manner. The behavior might cause
translation to fail or cause the translator or the resulting
program to behave in a non-conforming manner. Any such
pragma that is not recognized by the implementation is
ignored.

--
"If you want to post a followup via groups.google.com, don't use
the broken "Reply" link at the bottom of the article. Click on
"show options" at the top of the article, then click on the
"Reply" at the bottom of the article headers." - Keith Thompson


.



Relevant Pages

  • Re: padding mechanism in structures
    ... #pragma pack([n]) ... Specifies packing alignment for structure and union members. ... level by the pack pragma. ...
    (comp.lang.c)
  • Re: reading a C++ structure from a binary file using C#
    ... because it pragma pack was used several different values would be possible. ... The int is the first field of the struct, the second is a char array which has no alignment restriction, so, whatever the packing, the length written on disk will be 74. ... Padding is included in sizeof, because sizeof is the separation between adjacent array elements which must both be properly aligned. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Packing for __nogc classes
    ... not the library author's for failing to use a #pragma ... Windows.h, and all windows related header files, as well ... >packing through /Zp. ... Which is why I mentioned them in my first message to you. ...
    (microsoft.public.dotnet.languages.vc)
  • Re: Data alignment problems with sizeof and new
    ... It turned out to be a #pragma packwhich didn't ... restore the packing to normal. ... >>operators are not taking the alignment padding into account when calculating ... >>class with the first member being a dword size followed by doubles, ...
    (microsoft.public.vc.language)
  • Re: alignment problem / gcc compatibility
    ... If you use the /Zp4 switch, then offsetofequals 4, whereas ... The whole point of the packing settings is that you can make types appear at ... though there has been at least one notorious case where the #pragma was ...
    (microsoft.public.vc.language)