Compiler Directive to List Defined Macros?

Geoff Keating
Wed Jun 28 19:40:00 GMT 2000

Ross Combs <> writes:

> The reason I wanted to know was that I had some code like this:
>  #ifdef __func__
>    /* code using __func__ */
>  #else
>  # ifdef __PRETTY_FUNCTION__
>    /* code using __PRETTY_FUNCTION__ */
>  # else
>    /* code that doewsn't use function names */
>  # endif
>  #endif
> It kept acting like neither one was avaliable.  So I tried forcing it to use
> __func__, and I got compile errors.  I though that was strange, so I tried
> forcing it to use __PRETTY_FUNCTION__ and finally it worked.

I don't think you can reliably use #ifdef on __func__ or
__PRETTY_FUNCTION__.  This is because they're not macros.  They're
predefined static variables in every function's scope.

> I would suggest this should be made consistant.  It is nice to be able to
> support these extensions when they are avaliable, and detection through
> ifdef seems like the logical way to do so.

I believe that the new C standard specifies a standard way to do this,
and that GCC now does it in the standard way.  I forget what the exact
name is, perhaps __function__.

> (Also, I never got a response to my last email to this list about detecting
> multiple side effects and issuing a warning... does anyone care?  Is it such
> a horrible idea?)

It's not a bad idea.  Perhaps you could submit a patch?

- Geoffrey Keating <>

More information about the Gcc mailing list