I want to know how to find out if the preprocessor macro __PRETTY_FUNCTION__ can be used with a given compiler (As it is supposed to be non-standard). How do I check this in a header file? What I want to do is something like:
#ifndef __PRETTY_FUNCTION__
#define __PRETTY_FUNCTION__ __func__
#endif
But, I’m guessing what happens is the preprocessor defines the macro in place for each function so I wonder whether there’s any meaning to __PRETTY_FUNCTION__ (Unlike __FILE__ or __LINE__) outside a function. Is this true or can I just use the code above? If not, how do I check for it?
EDIT: I tried it. __PRETTY_FUNCTION__ is undefined outside a function (I didn’t check inside a class). So there has to be another way.
EDIT2: Actually a simple hack would be to do this :):
void Dummy()
{
#ifndef __PRETTY_FUNCTION__
#define __PRETTY_FUNCTION__ __func__
#endif
}
The other method is to check for compiler as was suggested by others.
You probably have to know which compiler you’re using. For GCC (the GNU Compiler Collection), you’d probably test:
You might check the compiler version if you know which one introduced the feature and you are in any danger of having your code compiled with an older version.
The GCC (4.4.1) manual says: