Packing
directives. These directives
tell the compiler how to pack the structure members.
This
directive can have two forms:
#pragma
pack(n)
where
n is 1,2,4,8, or 16. This will align
the members of a structure at 1 (i.e., no packing) at 2, 4, 8, or 16 bytes.
You
can also use:
#pragma
pack(push,n)
This
will save the current value of the packing constant, and set it to n,
which should be an integer as explained above. After some code, this allows you
to use:
#pragma
pack(pop)
to
restore the original value again.
Example:
The
most common use is at the beginning of an include file to set the value to a
certain amount, and to restore it at the end of the file.
#pragma
pack(push,1)
.....
#pragma pack(pop)
EOF
Include
directives. The pragma
#pragma
once
will
ensure that the current file will be read only once by the compiler. Any further
directives for #including the same file will have no affect.
Optimization
directives. This allows you to
set the optimization flag on or off at certain functions.
#pragma
optimize(n)
where
n will be either zero (no
optimizations) or one (optimizations).
Switch
generation control. The pragma
#pragma
density(push,0.0)
will
trigger the compiler to generate a table of all possible switch values between
the lowest and the highest case statements found, making a tradeoff that
penalizes space for speed. This can of course overflow if you have:
switch(i)
{
case
-10000000:
...
case
10000000:
...
}
In
this example, the generated table would have 20 million positions, which may not
be a good idea.
On the contrary, in
other cases where the numbers are densely packed, this can be an ideal
optimization.
Including libraries
for the link command
#pragma lib "mylib.lib"
#pragma lib <mylib.lib>
This pragmas allow you
to automatically include a library that is associated with a header file. Paths
enclosed in double quotes will be understood as absolute paths, paths enclosed
in <> will be searched in the standard library paths (normally \lcc\lib).