为什么改名不会破坏我的程序? [英] why name mangling isn't breaking my program?
问题描述
可能重复:
main()在C ++中是否已重载?
Possible Duplicate:
Is main() overloaded in C++?
这是我的代码:
#include <iostream>
int main(void* a, void* b)
{
std::cout << "hello standalone " << std::endl;
return 0;
}
名称修饰之后,不同的参数名称应具有不同的符号名称(void* a, void* b)
与(int, char**
应该不同),但是此程序在运行时没有任何问题.
different parameters should have a different symbol name after name mangling(void* a, void* b)
should be different from (int, char**
), but this program doesn't have any problem when running.
那是为什么?
推荐答案
因为main
是特例,编译器会为此生成特殊代码.通常,main
将从启动例程中调用-在较早的编译器中通常称为crt0
-用C编写,因此编译器将生成main
,就好像它被声明为extern "C"
一样.但这绝不是必需的.这只是一个典型的实现.
Because main
is a special case, and the compiler generates special code for it. Typically, main
will be called from a startup routine—often called crt0
in older compilers—written in C, so the compiler will generate main
as if it were declared extern "C"
. But that's in no way required; it's a just a typical implementation.
这篇关于为什么改名不会破坏我的程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!