这编译没有任何警告.
这在C和C++中是合法的还是只在gcc和clang中工作?
如果它是合法的,那么在C99之后它是新东西吗?
void f(){
}
void f2(){
return f();
}
Run Code Online (Sandbox Code Playgroud)
更新
正如"Rad Lexus"建议我试过这个:
$ gcc -Wall -Wpedantic -c x.c
x.c: In function ‘f2’:
x.c:7:9: warning: ISO C forbids ‘return’ with expression, in function returning void [-Wpedantic]
return f();
Run Code Online (Sandbox Code Playgroud)
$ clang -Wall -Wpedantic -c x.c
x.c:7:2: warning: void function 'f2' should not return void expression [-Wpedantic]
return f();
^ ~~~~~
1 warning generated.
Run Code Online (Sandbox Code Playgroud)
$ gcc -Wall -Wpedantic -c x.cc
(no errors)
Run Code Online (Sandbox Code Playgroud)
$ clang -Wall -Wpedantic -c x.cc
(no errors)
Run Code Online (Sandbox Code Playgroud)
更新 …