Each implementation of C and C++ supports some features unique to its host machine or operating system.
Some programs, for instance, need to exercise precise control over the memory areas where data is placed or
to control the way certain functions receive parameters.
The #pragma directives offer a way for each compiler
to offer machine- and operating-system-specific features
while retaining overall compatibility with the C and C++
languages. Pragmas are machine- or operating-system-specific by definition,
and are usually different for every compiler.
Syntax
#pragma token-string
The token-string is a series of characters that gives a specific compiler instruction and arguments,
if any.
The number sign (#) must be the first non-white-space character on the line containing the pragma;
white-space characters can separate the number sign and the word pragma.
Following #pragma, write any text that the translator can parse as preprocessing tokens.
The argument to #pragma is subject to macro expansion.
If the compiler finds a pragma it does not recognize, it issues a warning, but compilation continues.
Pragmas can be used in conditional statements, to provide new preprocessor functionality,
or to provide implementation-defined information to the compiler.
The C and C++ compilers recognize the following pragmas:
alloc_text comment init_seg1 optimize
auto_inline component inline_depth pack
bss_seg data_seg inline_recursion pointers_to_members1
check_stack function intrinsic setlocale
code_seg hdrstop message vtordisp1
const_seg include_alias once warning
This is an article from MSDN, I ever wanted to use
#pragma pack(1) //which can combine structure members to one continuous memory block
on MIPS platform using GCC, but it doesn't work.
See the compiler's document, it should be illustrated there.
Under linux env using intel-based GCC, it works.
Jul 23, 2008
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment