2

显然,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 开关?

4

1 回答 1

1

clangcpp是在传统的 cpp模式下进行预处理,其中 stringification#和 token-pasing## 没有任何意义

$ 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界面,还是可以使用该界面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
于 2013-11-08T15:33:56.953 回答