Re: padding mechanism in structures
- From: Lawrence Kirby <lknews@xxxxxxxxxxxxxxx>
- Date: Wed, 15 Jun 2005 14:56:38 +0100
On Wed, 15 Jun 2005 14:11:40 +0200, Mehta Shailendrakumar wrote:
> see if this helps with sample code attachment
> pack
> #pragma pack( [ n] )
Note that the C language doesn't define a preprocessor directive called
#pragma pack. You compiler may provide one as an extension but you can't
assume that it will exist on other compilers or if it does it will act in
the same way.
> Specifies packing alignment for structure and union members. Whereas the
> packing alignment of structures and unions is set for an entire
> translation unit by the /Zp option,
Again, compiler options are inherently compiler specific. Your compiler
might support such an option but you can't assume that others will. In
particular the original poster's compiler probably doesn't.
> the packing alignment is set at the
> data-declaration level by the pack pragma. The pragma takes effect at
> the first structure or union declaration after the pragma is seen; the
> pragma has no effect on definitions.
Since neither of these are C language features they aren't particularly
relevant to comp.lang.c. Also the question was more about how padding
works than how you might control it. In standard, portable C you can't.
> When you use #pragma pack(n), where n is 1, 2, 4, 8, or 16, each
> structure member after the first is stored on the smaller member type or
> n-byte boundaries. If you use #pragma pack without an argument,
> structure members are packed to the value specified by /Zp. The default
> /Zp packing size is /Zp8.
>
> The compiler also supports the following enhanced syntax:
Again, you mean *your* compiler. Usually the best thing to do with things
like #pragma pack is avoid them studiously since they are inherently
non-portable.
Lawrence
.
- Follow-Ups:
- Re: padding mechanism in structures
- From: Mehta Shailendrakumar
- Re: padding mechanism in structures
- References:
- padding mechanism in structures
- From: Roman Mashak
- Re: padding mechanism in structures
- From: Mehta Shailendrakumar
- padding mechanism in structures
- Prev by Date: Re: Printing a NULL pointer
- Next by Date: Re : padding mechanism in structures
- Previous by thread: Re: padding mechanism in structures
- Next by thread: Re: padding mechanism in structures
- Index(es):
Relevant Pages
|