Showing results for 
Search instead for 
Did you mean: 

#pragma pack() in linux

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.
Michael Steele_2
Honored Contributor

Re: #pragma pack() in linux

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:

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.
Support Fatherhood - Stop Family Law
Occasional Contributor

Re: #pragma pack() in linux

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

Re: #pragma pack() in linux


from the gcc documentation :

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));