This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: why does gcc fail to compile `printf("1 -- " __FUNCTION__ "\n")' ?
- From: Dan Hipschman <dsh at linux dot ucla dot edu>
- To: PRC <panruochen at gmail dot com>
- Cc: gcc-help <gcc-help at gcc dot gnu dot org>
- Date: Mon, 30 Jun 2008 20:16:59 -0700
- Subject: Re: why does gcc fail to compile `printf("1 -- " __FUNCTION__ "\n")' ?
- References: <200807011055026738249@gmail.com>
- Reply-to: dsh at linux dot ucla dot edu
On Tue, Jul 01, 2008 at 10:55:18AM +0800, PRC wrote:
> Hi All,
>
> I don't understand why gcc is unable to compile the following line:
> printf("1 -- " __FUNCTION__ "\n");
>
> but gcc can compile this line:
> printf("1 -- %s\n", __FUNCTION__);
>
> what's different between these two lines since __FUNCTION__ is a predefined macro which works as a const string?
It's not a string literal. See:
http://gcc.gnu.org/onlinedocs/gcc/Function-Names.html
Conceptually, the reason this need not work is that string concatenation
is done before syntatic analysis by the compiler (this is part of the
standard), so at the time adjacent string literals are concatenated, the
compiler may know nothing about what function, if any, the code is in.