gpt4 book ai didi

c++ - LLVM 预处理器显然不支持 ## 运算符?

转载 作者:太空宇宙 更新时间:2023-11-04 11:45:53 25 4
gpt4 key购买 nike

显然,clang/llvc cpp 命令不支持## 运算符

代码

sbo@linux:$ more x.c 
#define foo(a,b) (a ## b)

foo(one,two)

在 OSX 10.8 上我得到

osx108 stefanoborini$ cpp --version
Apple LLVM version 5.0 (clang-500.2.79) (based on LLVM 3.3svn)
Target: x86_64-apple-darwin12.5.0
Thread model: posix
osx108 stefanoborini$ cpp x.c
# 1 "x.c"
# 1 "<built-in>" 1
# 1 "<built-in>" 3
# 161 "<built-in>" 3
# 1 "<command line>" 1
# 1 "<built-in>" 2
# 1 "x.c" 2


(one ## two)

在 linux 上我得到

sbo@linux:$ cpp --version
cpp (Ubuntu/Linaro 4.6.3-1ubuntu5) 4.6.3
Copyright (C) 2011 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.

sbo@linux:$ cpp x.c
# 1 "x.c"
# 1 "<built-in>"
# 1 "<command-line>"
# 1 "x.c"


(onetwo)

是否有允许在 llvm 中使用 ## 运算符的 cpp 开关?

最佳答案

clang 的 cpp 正在 traditional-cpp 中进行预处理模式,其中字符串化 # 和标记粘贴 ## has no meaning .

$ cpp -### 1.c
Apple LLVM version 5.0 (clang-500.2.79) (based on LLVM 3.3svn)
Target: x86_64-apple-darwin13.0.0
Thread model: posix
...[snipped]... "-traditional-cpp" "-o" "-" "-x" "c" "1.c"

您必须使用 cpp 接口(interface),还是可以使用 clang -E 代替?

$ clang -E 1.c
# 1 "1.c"
# 1 "<built-in>" 1
# 1 "<built-in>" 3
# 162 "<built-in>" 3
# 1 "<command line>" 1
# 1 "<built-in>" 2
# 1 "1.c" 2


onetwo

关于c++ - LLVM 预处理器显然不支持 ## 运算符?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19861820/

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