This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: Compiler Directive to List Defined Macros?



I was going to ask a similar question today.  I tried the -E -dD options as
suggested and they do print out many of the predefined symbols.

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 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.

So I thought "maybe dynamic macros aren't detected by #ifdef".  I tried:
 #ifdef __LINE__
 # error __LINE__ is defined
 #endif

And it did indeed print the error message.

So a few things are going on:
 1) This version of gcc (egcs-2.91.66 from Red Hat 6.1) doesn't support
    __func__, but another version I used did.
 2) This version of gcc doesn't allow detection of __PRETTY_FUNCTION__ with
    #ifdef or #defined.

I know that #1 was "fixed" by version 2.95.1, because it works on another
machine using that version of gcc.

But is #2 "fixed" yet?  I tried it in version 2 with 2.95.1 and it still
didn't work.  The test for __LINE__ did work with 2.95.1 also.

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.

(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?)

Thanks for your time,
-Ross

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]