A
Alf P. Steinbach
Replace "debugger api" with "whatever" in this
<code>
#define USE_DEBUGGER_API // Or not
extern void useDebuggerApi();
#define CALL_IF_EXPANDED( doIt, f ) \
struct S_##f { \
struct Size2 { char x[2]; }; \
char foo( ... ) { return 0; } \
Size2 foo##doIt( int ) { return Size2(); } \
}; \
(sizeof( S_##f().foo(0) ) > 1 ? f() : (void)0)
#define CALL_IF( doIt, f ) CALL_IF_EXPANDED( doIt, f )
int main()
{
CALL_IF( USE_DEBUGGER_API, useDebuggerApi );
}
</code>
And why is it silly?
Well, if only routine is called in any particular build, then there could just
be a macro FUNCNAME, say, defined as the name of the routine to call.
But hey!
Actually I found a use for it.
I think (not sure yet).
Cheers,
- Alf
<code>
#define USE_DEBUGGER_API // Or not
extern void useDebuggerApi();
#define CALL_IF_EXPANDED( doIt, f ) \
struct S_##f { \
struct Size2 { char x[2]; }; \
char foo( ... ) { return 0; } \
Size2 foo##doIt( int ) { return Size2(); } \
}; \
(sizeof( S_##f().foo(0) ) > 1 ? f() : (void)0)
#define CALL_IF( doIt, f ) CALL_IF_EXPANDED( doIt, f )
int main()
{
CALL_IF( USE_DEBUGGER_API, useDebuggerApi );
}
</code>
And why is it silly?
Well, if only routine is called in any particular build, then there could just
be a macro FUNCNAME, say, defined as the name of the routine to call.
But hey!
Actually I found a use for it.
I think (not sure yet).
Cheers,
- Alf