Does the "C" standard support something similar to __func__ for the function arguments' names?
 
    
    - 391,730
- 64
- 469
- 606
- 
                    You will have to elaborate a bit on this... – Stephan202 May 25 '09 at 09:13
- 
                    2I think he means to ask if C has any macro that expands to the parameters of the function its in, and the answer is no. – Blindy May 25 '09 at 09:14
2 Answers
No, the C99 standard has the following:
6.10.8 Predefined macro names
The following macro names shall be defined by the implementation:
__DATE__ 
__FILE__ 
__LINE__ 
__STDC__ 
__STDC_HOSTED__ 
__STDC_MB_MIGHT_NEQ_WC__ 
__STDC_VERSION__ 
__TIME__ 
The following macro names are conditionally defined by the implementation:
__STDC_IEC_559__ 
__STDC_IEC_559_COMPLEX__ 
__STDC_ISO_10646__ 
6.4.2.2 Predefined identifiers
The identifier
__func__shall be implicitly declared by the translator as if, immediately following the opening brace of each function definition, the declaration
     static const char __func__[] = "function-name";
appeared, where function-name is the name of the lexically-enclosing function.63)
gcc adds some extensions, as I imagine other compilers do.
 
    
    - 48,893
- 5
- 92
- 171
if you want a quick and dirty solution for this make pre-processor macros like this...
#define FUNCTION_HEADER(a) a { const char* __func__ = #a;
#define FUNCTION_FOOTER() }
... and use it for your function headers and footers like this (tested with VS 2008):
#include <windows.h>
#define FUNCTION_HEADER(a) a { const char* __func__ = #a;
#define FUNCTION_FOOTER() }
FUNCTION_HEADER( int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd) )
    MessageBoxA(0, __func__, __func__, MB_OK);
    return 0;
FUNCTION_FOOTER()
This should work exactly how you want, but it is ugly.
 
    
    - 3,043
- 1
- 21
- 28