2

Apparently, clang/llvc cpp command does not support the ## operator

The code

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

foo(one,two)

On OSX 10.8 I get

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)

On linux I get

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)

Is there a cpp switch that allows the use of the ## operator in llvm ?

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
Stefano Borini
  • 138,652
  • 96
  • 297
  • 431
  • possible duplicate of [About ## preprocessor in C](http://stackoverflow.com/questions/11037153/about-preprocessor-in-c) – trojanfoe Nov 08 '13 at 15:02

1 Answers1

1

clang's cpp is preprocessing in the traditional-cpp mode, where stringification # and token-pasting ## 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"

Must you use the cpp interface, or could you use clang -E instead?

$ 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
kennytm
  • 510,854
  • 105
  • 1,084
  • 1,005
  • I tried to use `clang -E file.F90`, but then it complains as follows `error: invalid value 'f95-cpp-input' in '-x f95-cpp-input'`. I am actually preparsing a fortran file. – Stefano Borini Nov 08 '13 at 15:41
  • You should edit the question to show this. Also, you could install a real gcc via Homebrew or Macports which won't assume -traditional-cpp by default. – kennytm Nov 08 '13 at 15:49
  • `you could install a real gcc` not an option – Stefano Borini Nov 08 '13 at 16:08