[C] Hidden features of C - Programming On Unix

Users browsing this thread: 1 Guest(s)
bottomy
Registered
(08-01-2014, 09:56 PM)benwaffle Wrote: __FUNC__ in the preprocessor expands to the function being called
__LINE__ expands to the line number of the

example:
#define ERROR fprintf(stderr, "error at line %d in function %d", __LINE__, __FUNC__)

Also can't forget __FILE__, __DATE__, __TIME__, etc. For more standard predefined macros you can check the standard. For all predefined macros in your environment (assuming you're using GCC or Clang) you can use -dM or for the end of preprocessor stage -dD.

Your ERROR has a mistake, you meant for the second specifier to be %s not %d :) Also should be noted __func__ is the actual standard one, it is the actual identifier itself (it's not a macro). Though some compilers wrap __FUNC__ around __func__ (they also often provide others like __FUNCTION__, __PRETTY_FUNCTION__).


Messages In This Thread
[C] Hidden features of C - by benwaffle - 12-06-2013, 10:33 PM
RE: Hidden features of C - by yrmt - 13-06-2013, 08:29 AM
RE: Hidden features of C - by bottomy - 13-06-2013, 02:32 PM
RE: Hidden features of C - by bottomy - 20-06-2013, 02:41 AM
RE: Hidden features of C - by venam - 20-06-2013, 03:01 AM
RE: Hidden features of C - by Hans Hackett - 24-06-2013, 06:57 AM
RE: Hidden features of C - by benwaffle - 08-01-2014, 09:56 PM
RE: Hidden features of C - by bottomy - 09-01-2014, 03:54 AM
RE: [C] Hidden features of C - by dami0 - 24-07-2014, 07:23 PM
RE: [C] Hidden features of C - by jmbi - 25-07-2014, 12:43 AM