With gcc versions before 3.3 and with the MS compiler I use the following macro:
DEBUG_WARNING(...) printf(">WARNING: "__FUNCTION__"() " __VA_ARGS__);
Use:
DEBUG_WARNING("someFunction returned %d", ret);
Output:
>WARNING: Class::FunctionName() someFunction returned -1
Its extremely handy when we have lots of systems, all sending output. Its a single line macro, that allows us to filter the output accordingly. Small code, big use, happy me.
As the __FUNCTION__ (and __func__ in C++) definition has changed (to make it standards compliant I believe) it has also made that macro unworkable.
I’ve got it working using a function that builds the string by hand, but I like my macro.
Am I missing an easy way to get this simple one line macro to still work under Gcc 3.3?
: D
Since
__FUNCTION__and__func__is a predefined identifier and not a string literal, you cannot use it in preprocessor string literal concatenation. But you can use it inprintfformatting. Also note the use of##argsinstead of__VA_ARGS__to use GNU style variadic macro arguments to work around the issue with the comma between__func__and possibly zero args.