C ++ Concatinating __func__和const char文字 [英] C++ Concatinating __func__ and const char literal
问题描述
我试图在C ++中concordate __ func__和文字字符串,并且我在GCC(有或没有C ++ 11 standart)上出错。例如,像这样:
#include
int main(void)
{
printf(%s,__func__try#1 \\\
);
printf(__ func__try#2 \\\
);
返回0;
}
看起来像__ func__实际上不是字符串文字宏。有人知道为什么会发生这种情况,也许是解决这个问题的方法吗?
从技术上讲, __ func__
是一个预定义的标识符。它是从不实现为一个宏。
它的类型为 static const char __func __ [] $ c $因此你不能按照你的方式连接它。当然,你可以将它添加到
std :: string
中。
使用
printf(%s try#1 \\\
,__func __);
代替。
I am trying to concatinate __ func__ and literal string in C++ and I am getting an error on GCC (with or without of C++11 standart). Like, for example, here:
#include <cstdio>
int main(void)
{
printf("%s", __func__ " try #1\n");
printf(__func__ " try #2\n");
return 0;
}
Looks like __ func__ is not actually a string literal macros. Does anyone knows why that is happening and, maybe, way to solve it?
Technically, __func__
is a predefined identifier. It's never implemented as a macro.
It has the type static const char __func__[]
and so therefore you can't concatenate it the way you have. Of course, you can add it to a std::string
though.
Use
printf("%s try #1\n", __func__);
instead.
这篇关于C ++ Concatinating __func__和const char文字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!