gcc是通过文件名后缀来判断源代码语言类型的。
如果你从标准输入把源码传给gcc,那么就需要通过-x
选项显式的指定语言类型:
$ echo "int x;" | gcc -S -x c -
$ cat ./-.s
.file ""
.comm x,4,4
.ident "GCC: (Ubuntu/Linaro 4.6.3-1ubuntu5) 4.6.3"
.section .note.GNU-stack,"",@progbits
You can specify the input language explicitly with the -x option:
-x language
Specify explicitly the language for the following input files (rather than letting the compiler choose a default based on the file name suffix). This option applies
to all following input files until the next -x option. Possible values for language are:
c c-header cpp-output
c++ c++-header c++-cpp-output
objective-c objective-c-header objective-c-cpp-output
objective-c++ objective-c++-header objective-c++-cpp-output
assembler assembler-with-cpp
ada
f77 f77-cpp-input f95 f95-cpp-input
go
java