Isn't __FUNCTION__
字符串文字?我一直以为是这样的__FILE__
,但我刚刚发现我无法将字符串文字与其相邻连接。如果它不是字符串文字,那么它的定义是什么?我无法让 cscope 解决它。
E.g.
#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__
字符串文字?
No.
From https://gcc.gnu.org/onlinedocs/gcc-7.2.0/gcc/Function-Names.html https://gcc.gnu.org/onlinedocs/gcc-7.2.0/gcc/Function-Names.html
这些标识符是变量,而不是预处理器宏,并且不能用于初始化字符数组或与字符串文字连接。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)