为什么不能将字符串文字连接到__FUNCTION__? [英] Why can't a string literal be concatenated to __FUNCTION__?
本文介绍了为什么不能将字符串文字连接到__FUNCTION__?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
不是__FUNCTION__
字符串文字吗?我一直以为是-沿__FILE__
的意思,但是我发现不能将字符串文字与其相邻地连接.如果它不是字符串文字,它的定义是什么?我无法让cscope解决它.
Isn't __FUNCTION__
a string literal? I'd always thought it was - along the lines of __FILE__
, but I just discovered I can't adjacently concatenate a string literal to it. If it's not a string literal, what is it defined as? I can't get cscope to resolve it.
例如
#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.
推荐答案
不是
__FUNCTION__
字符串文字吗?
否.
来自 https://gcc.gnu.org /onlinedocs/gcc-7.2.0/gcc/Function-Names.html
这些标识符是变量,而不是预处理器宏,并且不能用于初始化char数组或与字符串文字串联.
These identifiers are variables, not preprocessor macros, and may not be used to initialize char arrays or be concatenated with string literals.
这篇关于为什么不能将字符串文字连接到__FUNCTION__?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文