相关疑难解决方法(0)

在C和C++中返回void类型

这编译没有任何警告.

这在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)

更新 …

c c++ gcc clang language-lawyer

65
推荐指数
3
解决办法
9538
查看次数

标签 统计

c ×1

c++ ×1

clang ×1

gcc ×1

language-lawyer ×1