This is the mail archive of the 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]
Other format: [Raw text]

Re: concatenating __FUNCTION__

>>>>> "Kevin" == Kevin Nomura <> writes:

    Kevin> gcc 3.0 warns about concatenating __FUNCTION__ with a
    Kevin> string literal:

    Kevin> [tyrell]$ gcc-3.0.3/bin/gcc a.c a.c: In function `main':
    Kevin> a.c:3: warning: concatenation of string literals with
    Kevin> __FUNCTION__ is deprecated.  This feature will be removed
    Kevin> in future [tyrell]$ cat a.c main() { printf ("%s\n",
    Kevin> __FUNCTION__ "hi"); }

    Kevin> I find this odd given that the manual explicitly calls out
    Kevin> this capability as a feature (section 5.41, "Function Names
    Kevin> as Strings") in contrast with __func__:

    Kevin> "This means that they catenate with other string literals,
    Kevin> and that they can be used to initialize char arrays".

    Kevin> I see no mention of deprecation.  Initializing a char array
    Kevin> with __FUNCTION__ does not get a warning.

    Kevin> Is __FUNCTION__ itself deprecated?  (If not, why would the
    Kevin> existing ability to concatenate it be dropped?)  Thanks in
    Kevin> advance for clarification.

To quote the gcc info manual:

|    The compiler automagically replaces the identifiers with a string
| literal containing the appropriate name.  Thus, they are neither
| preprocessor macros, like `__FILE__' and `__LINE__', nor variables.
| This means that they catenate with other string literals, and that they
| can be used to initialize char arrays.
| [...]
|    Note that these semantics are deprecated, and that GCC 3.2 will
| handle `__FUNCTION__' and `__PRETTY_FUNCTION__' the same way as
| `__func__'.  `__func__' is defined by the ISO standard C99:
|      The identifier `__func__' is implicitly declared by the translator
|      as if, immediately following the opening brace of each function
|      definition, the declaration
|           static const char __func__[] = "function-name";
|      appeared, where function-name is the name of the lexically-enclosing
|      function.  This name is the unadorned name of the function.
|    By this definition, `__func__' is a variable, not a string literal.
| In particular, `__func__' does not catenate with other string literals.


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