why name mangling isn't breaking my program? [duplicate]

心不动则不痛 提交于 2019-12-11 07:59:37

问题


Possible Duplicate:
Is main() overloaded in C++?

here's my code:

#include <iostream>

int main(void* a, void* b)
{
    std::cout << "hello standalone " << std::endl;                      
    return 0;
}

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.

Why is that?


回答1:


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.




回答2:


It depends on the compiler. The standard required signatures for main are:

int main()
int main(int argc, char** argv)
int main(int argc, char* argv[])

But besides these, the compiler is free to provide other signatures as well.

For example, gcc 4.3.4 rejects your code - http://ideone.com/XZp2h

MSVS complains about unresolved externals.



来源:https://stackoverflow.com/questions/10715689/why-name-mangling-isnt-breaking-my-program

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!