1828225 Members
2514 Online
109975 Solutions
New Discussion

#pragma pack() in linux

 
satish_16
Occasional Contributor

#pragma pack() in linux

what is a #pragma pack()? how to use it in gcc compiler.
send me the answer as soon as possible.
3 REPLIES 3
Michael Steele_2
Honored Contributor

Re: #pragma pack() in linux

pragma
An ANSI C command comment that conveys non-essential yet pragmatic information, often to help with optimization when compiling.

Here is a Red Hat link:

http://www.redhat.com/docs/manuals/gnupro/GNUPro-Toolkit-00r1/pdf/2_compile.pdf

Here is some HP info:

You typically use a #pragma directive to control the actions of the compiler in a particular portion of a translation unit without affecting the translation unit as a whole.

http://docs.hp.com/cgi-bin/otsearch/getfile?id=/hpux/onlinedocs/1559/pragmas.htm&searchterms=pragma&queryid=20030327-055643
Support Fatherhood - Stop Family Law
satish_16
Occasional Contributor

Re: #pragma pack() in linux

hi,
Thanks for the information.
currently i am working with linux.i want's to use the #pragma pack() in nested structures.so please send me the
syntax with an example.
Goran Koruga
Honored Contributor

Re: #pragma pack() in linux

Hi,

from the gcc documentation :

`packed'
The `packed' attribute specifies that a variable or structure field
should have the smallest possible alignment--one byte for a
variable, and one bit for a field, unless you specify a larger
value with the `aligned' attribute.

Here is a structure in which the field `x' is packed, so that it
immediately follows `a':

struct foo
{
char a;
int x[2] __attribute__ ((packed));
};

HTH,Goran