__FUNCTION__
不是字符串文字吗?我一直认为它是 - 沿着 __FILE__
的路线,但我刚刚发现我不能将字符串文字相邻地连接到它。如果它不是字符串文字,它被定义为什么?我无法让 cscope 解决它。
例如
#include <iostream>
int main( int argc, char* argv[] )
{
std::cout << __FILE__ << std::endl;
std::cout << __FILE__ "A" << std::endl;
std::cout << __FUNCTION__ << std::endl;
//std::cout << __FUNCTION__ "A" << std::endl; // Doesn't compile.
return 0;
}
包含问题行时的错误:
>g++ --version
g++ (GCC) 4.8.3 20140911 (Red Hat 4.8.3-7)
Copyright (C) 2013 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
>g++ -g main.cpp
main.cpp: In function 'int main(int, char**)':
main.cpp:8:29: error: expected ';' before string constant
std::cout << __FUNCTION__ "A" << std::endl; // Doesn't compile.
最佳答案
Isn't
__FUNCTION__
a string literal?
没有。
来自 https://gcc.gnu.org/onlinedocs/gcc-7.2.0/gcc/Function-Names.html
These identifiers are variables, not preprocessor macros, and may not be used to initialize char arrays or be concatenated with string literals.
关于c++ - 为什么不能将字符串文字连接到 __FUNCTION__?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48124994/