Can a void-returning function g return f(); when f returns void?

后端 未结 3 1194
不知归路
不知归路 2020-12-30 23:26

Consider the following snippet:

void f(void);

void g(…)
{
  …
  return f();
  …
}

Is this return f(); valid according to C11?

3条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2020-12-31 00:06

    It clearly states A return statement without an expression shall only appear in a function whose return type is void, try and execute this:

    void g()
    {
        return; // does not return any expression at all
    }
    void f()
    {
        return g();
    }
    
    
    int main(void) {
        f();
        return 0;
    }
    

提交回复
热议问题