Wednesday, November 16, 2011

C programming, Pre-defined Macro's

A typical example of using predefined macros is for reporting error conditions in a generic macro so you can find your way in the to where the problem occurred.

fprintf (stderr, "Internal error: negative string length %d at %s, line %d.",length, __FILE__, __LINE__);

__FILE__
__LINE__
__func__ (c99) and __FUNCTION__(GCC)


Information about compile
__DATE__
__TIME__


Date and time are precious to know exactly what binary you are running, with embedded systems this come up often.

__STDC__
__STDC_VERSION__  (doesn't work for me, but it's in doc's) 
__STDC_HOSTED__




__cplusplus
__OBJC__


http://gcc.gnu.org/onlinedocs/cpp/Standard-Predefined-Macros.html
http://gcc.gnu.org/onlinedocs/cpp/Common-Predefined-Macros.html
http://gcc.gnu.org/onlinedocs/cpp/System_002dspecific-Predefined-Macros.html

No comments: