Gcc 通过引用传递变量
我正在使用clang 3.4.2编译以下代码Gcc 通过引用传递变量,gcc,clang,Gcc,Clang,我正在使用clang 3.4.2编译以下代码 #include <stdio.h> void haa(int& j){ j=1; } int main(){ printf("hello\n"); } 使用gcc编译相同的代码不会出现错误或警告。。。 有人能解释为什么会发生这样的事情吗? < P>问题是,通过引用(引用和非指针)不是C而是C++特性。p> < >你需要用C++编译器编译代码,比如 G++< /COD>或 CLAN++。将文件扩展名改为> CPP
#include <stdio.h>
void haa(int& j){
j=1;
}
int main(){
printf("hello\n");
}
使用gcc编译相同的代码不会出现错误或警告。。。
有人能解释为什么会发生这样的事情吗? < P>问题是,通过引用(引用和非指针)不是C而是C++特性。p>
< >你需要用C++编译器编译代码,比如<代码> G++< /COD>或<代码> CLAN++<代码>。将文件扩展名改为
haa
重命名为hab
会有所不同吗?在haa之前添加新行怎么样?不,没有任何区别。。我收到了相同的错误消息。。正如您在错误消息中所看到的,clang正在抱怨符号符号,即通过引用传递变量..啊,是的,这不是有效的C,对吗?如果你用clang++编译它,它会工作的。谢谢!我忘了!
hello.c:3:13: error: expected ')'
void haa(int& j){
^
hello.c:3:9: note: to match this '('
void haa(int& j){
^
hello.c:3:13: error: parameter name omitted
void haa(int& j){
^
hello.c:4:2: error: use of undeclared identifier 'j'
j=1;
^
3 errors generated.