链接具有不同 return 类型的函数

Linking functions with different return types

0.c

int test();
int main(){
 return test();
}

1.c

void test(){
 //
}

上面的 gcc 0.c 1.c 和 main returns 0 编译得很好。 这是未定义的行为吗?因为 test 技术上没有 return 任何东西。

与 C++ 相反,C 不会在函数的外部名称中存储它们的 return 类型和参数类型。它仅指定(相对于提供的代码)存在用于链接的函数的外部名称test

至于 C++ 那么例如在 MS VC++ 的文档中有关于修饰名的文章

If you change the function name, class, calling convention, return type, or any parameter, the decorated name also changes. In this case, you must get the new decorated name and use it everywhere the decorated name is specified.

经过修饰的名称是在 C++ 中实现定义的。

因此,问题中提供的代码具有未定义的行为。