2 Replies Latest reply: Apr 21, 2014 2:06 PM by Ivanigorovich-Oracle RSS

    Introduce macro __FUNCTION__?

    2653080

      There is a very convenient set of predefined macros - __FILE__, __LINE__ and __FUNCTION__. These defines work in GCC, ICC, MSVC, clang.

      But, unfortunately macro __FUNCTION__ is absent in Solaris Studio 12.3. Would you please introduce this predefined macro in the next version of Solaris Studio? Of course, if it does not break anything.

       

      It should work similar to __LINE__, __FILE__ i.e. like a string literal.

       

      P.S.

      I know that it is not standart, but it is very convenient and supported by mainstream compilers.

        • 1. Re: Introduce macro __FUNCTION__?
          Fedor-Oracle

          Is there any difference in convenience between __FUNCTION__ and __func__ (which is a standard way to query function name)?

          __func__ is similarly supported by all the mainstream compilers and has a benefit of being standard.

          If you have an old code that uses __FUNCTION__ you can easily define __FUNCTION__=__func__.

           

          regards,

          __Fedor.

          • 2. Re: Introduce macro __FUNCTION__?
            Ivanigorovich-Oracle

            I tried CC 12.3 and if you put something like this in your code:

                printf("func is %s\n", __func__);

            then it apparently creates not one but three local variables which

            you can see in dbx:

            (dbx) dump                                                      

            __FUNCTION__ = "main"

            __PRETTY_FUNCTION__ = "int main()"

            __func__ = "main"

            gdb will generate __func__ as a local but defines __FUNCTION__ as a macro.

             

            The advantage of a macro is that it won't pollute the locals window

            in the IDE with needless information. With macros you can also

            do string and macro gluing.