本文介绍了使用预处理器的字符串连接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否可以在预处理期间连接字符串?
is it possible to concatenate strings during preprocessing?
我发现此示例
#define H "Hello "
#define W "World!"
#define HW H W
printf(HW); // Prints "Hello World!"
但是它不适用于我 - 当我使用 gcc -std = c99
However it does not work for me - prints out "Hello" when I use gcc -std=c99
UPD 此示例看起来像现在工作。
UPD This example looks like working now. However, is it a normal feature of c preprocessor?
推荐答案
邻接字符串乱序的连接不是预处理器的一个特性,它是核心语言(C和C ++)的一个特性。您可以写:
Concatenation of adjacent string litterals isn't a feature of the preprocessor, it is a feature of the core languages (both C and C++). You could write:
printf("Hello "
" world\n");
这篇关于使用预处理器的字符串连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!