Please pardon me if I am asking an obvious question,
but after going through a bunch of threads and trying out stuff, I am not able to pin down this simple thing.
I have this small program:
#define FUNC_PREFIX __FUNCTION__ "() :"
int main()
{
printf("%s\n", FUNC_PREFIX);
return 0;
}
So I can pass FUNC_PREFIX instead of __FUNCTION__ to log functions and they will print the calling function name followed by paren and colon — just so to improve readability of log line outputs.
This compiles fine as-is in Visual Studio 2008.
But in g++, I get an error expected ‘)’ before string constant
I tried a few things like doing:
#define TEMP __FUNCTION__
#define FUNC_PREFIX TEMP "() :"
but to no avail.
What is the way to go about doing this?
Your printf is missing a quote. Use identifier
__func__and you can print two strings if you define the macro as: