Borland C++这个bool函数会返回什么?

use*_*718 2 c++ borland-c++

bool SomeFunction()
{

}
Run Code Online (Sandbox Code Playgroud)

我无法在我的机器上运行Borland C++,但我需要从C++转换为VB,因此需要有关此功能的帮助.

jua*_*nza 10

该函数声称它返回a bool但它什么都不返回.这应该导致编译器警告.如果你使用它来分配调用函数的东西,结果将是未定义的行为:

bool b = SomeFunction(); // UB, SomeFunction is failing to return.
SomeFunction(); // still undefined behaviour
Run Code Online (Sandbox Code Playgroud)

main()允许不显式返回,在这种情况下它会隐式返回0.

看这里:

§6.6.3/ 2:

流出函数末尾相当于没有值的返回; 这会导致值返回函数中的未定义行为.