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

Re: why does gcc fail to compile `printf("1 -- " __FUNCTION__ "\n")' ?


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.


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