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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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 of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux