This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: Compiler Directive to List Defined Macros?
- To: rocombs at cs dot nmsu dot edu
- Subject: Re: Compiler Directive to List Defined Macros?
- From: "Martin v. Loewis" <martin at loewis dot home dot cs dot tu-berlin dot de>
- Date: Thu, 29 Jun 2000 09:38:32 +0200
- CC: gcc at gcc dot gnu dot org
- References: <200006290019.SAA23796@quito.cs.nmsu.edu>
> A few things seem to be missing though. It doesn't show __FILE__, __LINE__,
> __func__, or __PRETTY_FUNCTION__. I understand these are a little different
> since they are "dynamic", but it would be helpful to know which ones are
> avaliable.
The complete list can be found be combining those required by the
standard with those documented in the GCC documentation, in particular
in the section "Function Names".
> The reason I wanted to know was that I had some code like this:
> #ifdef __func__
> /* code using __func__ */
> #else
As Geoff explains, __func__ is not a preprocessor macro. Instead, it
is an identifier. The proper way of testing for it is to write
#if __STDC_VERSION__+0 >= 199901L
since __func__ is defined by C99.
> # ifdef __PRETTY_FUNCTION__
> /* code using __PRETTY_FUNCTION__ */
> # else
> /* code that doewsn't use function names */
> # endif
> #endif
The proper way of testing for these is to write
#ifdef __GNUC__
in which case you can use either one.
> 1) This version of gcc (egcs-2.91.66 from Red Hat 6.1) doesn't support
> __func__, but another version I used did.
Yes, I believe it was added in 2.95.
> 2) This version of gcc doesn't allow detection of __PRETTY_FUNCTION__ with
> #ifdef or #defined.
No, that is not possible - the preprocessor has no way of knowing what
the current function is. That's why they are identifiers, or string
literals.
> But is #2 "fixed" yet?
It's not broken. It can't possibly work the way you expect it to
work. Instead, you must use other tests in portable code.
Regards,
Martin