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

时间:2013-11-08 14:47:42

标签: c++ concatenation c-preprocessor llvm

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

1 个答案:

答案 0 :(得分:1)

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界面,还是可以使用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