Subject: Re: [boost] String literals concatenation issue when usingBOOST_CURRENT_FUNCTION
From: vicente.botet (vicente.botet_at_[hidden])
Date: 2010-01-16 11:05:21
----- Original Message -----
From: "vicente.botet" <vicente.botet_at_[hidden]>
Sent: Saturday, January 16, 2010 4:37 PM
Subject: [boost] String literals concatenation issue when usingBOOST_CURRENT_FUNCTION
I want to define a macro as
#define BOOST_CHRONO_DIGITAL_TIME_FORMAT(F) "\n" F " tokes %d day(s) %h:%m:%s.%n\n"
#define BOOST_CHRONO_DIGITAL_TIME_FUNCTION_FORMAT BOOST_CHRONO_DIGITAL_TIME_FORMAT(BOOST_CURRENT_FUNCTION)
I have a compile error with gcc(3.4.4 or 4.4.0) (Boost v1.41) in the following sentence
const char* c= "\n" BOOST_CURRENT_FUNCTION " %d day(s) %h:%m:%s.%n\n";
C:\cygwin\boost_1_41_0\libs\chrono\example\digital_time_example.cpp: In function `int f1(long int)':
C:\cygwin\boost_1_41_0\libs\chrono\example\digital_time_example.cpp:24: error: expected `;' before "__PRETTY_FUNCTION__"
as well as
const char* c= "\n" __PRETTY_FUNCTION__ " %d day(s) %h:%m:%s.%n\n";
The same code works as I expected with MSVC.
The following code works well with gcc
const char* c= "\n" "f" " %d day(s) %h:%m:%s.%n\n";
const char* c2= BOOST_CURRENT_FUNCTION;
as well as this one
const char* c= "\n" __FILE__" %d day(s) %h:%m:%s.%n\n";
Is there something wrong? Does gcc manage __PRETTY_FUNCTION__ and __FILE__ differently? Does someone knows a workaround?
Vicente Juan Botet Escribá
Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost
Well I have found this
"These identifiers are not preprocessor macros. In GCC 3.3 and earlier, in C only, __FUNCTION__ and __PRETTY_FUNCTION__ were treated as string literals; they could be used to initialize char arrays, and they could be concatenated with other string literals. GCC 3.4 and later treat them as variables, like __func__. In C++, __FUNCTION__ and __PRETTY_FUNCTION__ have always been variables."
Unfortunately I think that I will be unable to define my macro in a portable way.
Does some one know why it is preferable that in C++ __FUNCTION__ and __PRETTY_FUNCTION__ be variables?
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk