This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

__FUNCTION__ and __func__



Based on a customer issue (he complained that __LINE__ and __func__ did not work, but that __FILE__ and __FUNCTION__ did), I ran a quick test using C6000 CGT 7.3.1 and discovered that all of them seemed to work just fine. But  __func__ (which is apparently C99 standard) and __FUNCTION__ (which isn't standardized but apparently GCC and maybe other compilers supported before C99) are not documented in section 2.6.1 (Predefined Macro Names) of the compiler user's guide. 

Is this an oversight? Is there any reason we can't or shouldn't use these?  Will any compiler options (like --gcc) alter the operation of these?

Thanks, Daniel

  • The documentation seems to be missing a number of predefined macros.

    The non-standard (but available in GCC compilers) __FUNCTION__, __PRETTY_FUNCTION__ and __BASE_FILE__ are always defined.

    __func__ is a slightly different animal.  It is a predefined identifier; the others are predefined macros.  As a predefined identifier it follows normal block scoping rules (unlike macros).  __func__ behaves as if the following declaration appears after the opening brace of each function definition:

        static const char __func__ [] = "function-name";

    __func__ is available only when either the --gcc or --relaxed_ansi option is in effect.

     

  • Paul,

    Thanks for the explanation and clarification.  It turns out the CCS project I tested with had --gcc defined, so __func__ worked for me right off the bat.

    Will the documentation be updated to reflect these and any other missing defines?  With regard to identifiers versus macros, are there other predefined identifiers besides  __func__?

    Regards, Daniel

  • so my error with __LINE__ was that i mistakenly was using a %s format instead of %d, and for __func__ was that I neglected to include <stdio.h>.  So yes they all work for me too.  Doc needs to be updated but I would expect they should be kept in!

    thanks.

  • Daniel,

    I believe __func__ is the only predefined identifier defined by C99.