When #pragma first came into usage, the people behind GCC
weren't able to put in support for it right away, so instead they quickly hacked in a very odd little quick-fix.
With these certain earlier versions of gcc, if you compiled a file containing a #pragma, GCC would attempt each of the following in turn:
- Attempt to launch a game of nethack.
- Attempt to launch a game of rogue.
- Attempt to launch a game of Towers of Hanoi via emacs.
- Print the message "You are in a maze of twisty compiler features, all different."
I don't think the GCC people liked the idea of #pragma very much.
The thing about #pragma is that it has no standard behavior.
Oh, #pragma itself is standard, all right-- it's just the arguments you give #pragma aren't.
They vary completely from compiler to compiler.
#pragma is just kind of the standard way for a compiler to give an interface to do nonstandard things-- by definition, #pragma arguments are to be interpreted in whatever arbitrary way the compiler decides. Meaning the old GCC "feature" above was not an easter egg as some have claimed, but actual support for #pragma-- just an odd implementation, that's all.
The problem with this is that it's perfectly accepted for compilers to introduce pragma directives with the same keyname but different effects-- meaning . Ariels has an excellent example of how this can get painful in #pragma is useless. This is why even today GNU tries to avoid #pragma to the greatest extent possible, using language extentions such as are described in Ariels' node and in some cases (though i can't seem to find the exact documentation) having the programmer #define specific strings in order to denote which gcc-specific compilation options they wish to use. When they do use #pragma for things, they request programmers preface their #pragma calls with "GCC" in order to prevent ugly namespace collisions and ugly ifdef cludges.
#pragma directives in Codewarrior (this list is incomplete, and will be added to when i finally find my documentation cd)
- #pragma mark label
- The Codewarrior IDE has this nifty little feature where all the editor windows are fitted with pop-up menus listing all the functions in the current file, sorted by location. Choose the function from the menu, and the window automatically scrolls the document to that function for you. You have no idea how addictive this feature becomes.
#pragma mark label adds an item named label to the menu; selecting label jumps you to the #pragma. You can also say #pragma mark -, which adds a divider to the menu.. meaning you can cleanly arrange your functions into logical groups within the menu.
- #pragma unused variable
- You put this at the beginning of a function to tell the compiler that the passed variable variable is not used in the function. Supposedly the variable is still compiled in and passed and allocated and everything-- all this directive does is disable the irritating compiler warning.
#pragma directives in gcc (These are the preprocessor-handled directives only. I'm still looking for the compiler #pragma docs.)
- #pragma GCC system_header
- This tells GCC to consider everything after the pragma to be system headers. The effect this is that certain types of compiler warnings, esp. the ones generated by the -pedantic flag, are ignored, under the logic that OS and runtime libraries shouldn't be expected to be strictly conforming C. You can get this same effect using the -I and -isystem compiler flags; see the manpage.
This directive has no effect in the primary source file (main()?); it only works on #included files.
- #pragma GCC poison identifiers
- This directive bans usage of the identifiers within the program. Poisoned identifiers cannot be #ifdef'd or #undef'd, and attempting to use them for anything will produce an error. Identifiers is a list, separated by spaces.
- #pragma GCC dependency "filename" message
- If file filename is newer than the file containing this #pragma, a warning is issued containing the error message message.
" in each of the above is part of the namespacing
in the C99
standard. For backwards compatibility
reasons, the gcc can
be left out, but it shouldn't be.
gcc info gathered from http://www.gnu.org/software/gcc/onlinedocs/cpp_1.html