gpt4 book ai didi

C++ 预处理器删除可变参数宏调用中的空格 (Solaris Studio 12.3)

转载 作者:可可西里 更新时间:2023-11-01 15:24:52 27 4
gpt4 key购买 nike

Oracle Solaris Studio 12.3 的 C++ 预处理器在扩展 __VA_ARGS__ 时完全删除了空格。

任何人都可以在他们的系统上确认这种行为吗?这是一个已知的编译器错误吗?这个问题有什么解决方法吗?

为了说明,这里有一个简单的测试程序,vaargs.c:

#include <stdio.h>

#define PRINT(...) printf("%s\n", #__VA_ARGS__)

int main()
{
PRINT(hello world);

return 0;
}

C 预处理器按预期工作:

$ cc vaargs.c -o vaargs && ./vaargs
hello world

$ cc -V
cc: Sun C 5.12 SunOS_i386 2011/11/16

但是 C++ 预处理器删除了“hello”和“world”之间的空格:

$ CC vaargs.c -o vaargs && ./vaargs
helloworld

$ CC -V
CC: Sun C++ 5.12 SunOS_i386 2011/11/16

最佳答案

根据 N3337,这是一个编译器错误16.3.2 (cpp.stringize) p2(引用的其余部分被截断):

A character string literal is a string-literal with no prefix. If, in the replacement list, a parameter is immediately preceded by a # preprocessing token, both are replaced by a single character string literal preprocessing token that contains the spelling of the preprocessing token sequence for the corresponding argument. Each occurrence of white space between the argument’s preprocessing tokens becomes a single space character in the character string literal.

关于C++ 预处理器删除可变参数宏调用中的空格 (Solaris Studio 12.3),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26219063/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com