I was wondering if the following technique will produce undefined behavior:
_______________
#include <cstdio>
#define CALL_MACRO_FUNC TION(func_ptr)f unc_ptr()
#define MY_MESSAGE() "Press <ENTERto exit."
int main(void) {
puts(CALL_MACRO _FUNCTION(MY_ME SSAGE));
getchar();
return 0;
}
_______________
I define 'MY_MESSAGE' as a macro function and only pass the name of it to
'CALL_MACRO_FUN CTION' which in turn uses the name to actually invoke it. The
name of a macro function is analogous to a function pointer. This is useful
when you need to have precise control over when a macro will actually
expand.
--
Chris M. Thomasson
_______________
#include <cstdio>
#define CALL_MACRO_FUNC TION(func_ptr)f unc_ptr()
#define MY_MESSAGE() "Press <ENTERto exit."
int main(void) {
puts(CALL_MACRO _FUNCTION(MY_ME SSAGE));
getchar();
return 0;
}
_______________
I define 'MY_MESSAGE' as a macro function and only pass the name of it to
'CALL_MACRO_FUN CTION' which in turn uses the name to actually invoke it. The
name of a macro function is analogous to a function pointer. This is useful
when you need to have precise control over when a macro will actually
expand.
--
Chris M. Thomasson
Comment