String literals concatenation issue when using BOOST_CURRENT_FUNCTION

Hi, 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? Best, _____________________ Vicente Juan Botet Escribá

----- Original Message ----- From: "vicente.botet" <vicente.botet@wanadoo.fr> To: <boost@lists.boost.org> Sent: Saturday, January 16, 2010 4:37 PM Subject: [boost] String literals concatenation issue when usingBOOST_CURRENT_FUNCTION Hi, 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? Best, _____________________ Vicente Juan Botet Escribá _______________________________________________ Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost With __FUNCTION__ doesn't works neither.

vicente.botet wrote:
Hi,
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?
Yes. __PRETTY_FUNCTION__ is not a string literal. From the gcc manual: "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." John Bytheway

----- Original Message ----- From: "vicente.botet" <vicente.botet@wanadoo.fr> To: <boost@lists.boost.org> Sent: Saturday, January 16, 2010 4:37 PM Subject: [boost] String literals concatenation issue when usingBOOST_CURRENT_FUNCTION Hi, 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? Best, _____________________ 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? Vicente
participants (2)
-
John Bytheway
-
vicente.botet