From mboxrd@z Thu Jan 1 00:00:00 1970 From: "Martin v. Loewis" To: rocombs@cs.nmsu.edu Cc: gcc@gcc.gnu.org Subject: Re: Compiler Directive to List Defined Macros? Date: Thu, 29 Jun 2000 00:39:00 -0000 Message-id: <200006290738.JAA00908@loewis.home.cs.tu-berlin.de> References: <200006290019.SAA23796@quito.cs.nmsu.edu> X-SW-Source: 2000-06/msg00743.html > 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