C++ ODR

来源:互联网 发布:mac可以玩魔兽世界 编辑:程序博客网 时间:2024/05/18 03:29

对于相同的代码,使用CC以及cc编译的目标文件结果函数名变化。

 

C++对于违反ODR的程序链接时做的不好。

 

Forexample,

 

//static

void fun(int a)

{

}

 

int main()

{

        return 0;

}

 

 

UsingCC,

  1. uncomment static,

[5]    |        16|      64|FUNC |LOCL |0    |2     |void fun(int)

                                                      [__1cDfun6Fi_v_] (C++ Name Mangling)

  1. comment static,

[12]   |        16|      64|FUNC |GLOB |0    |2     |void fun(int)

                                                      [__1cDfun6Fi_v_] (C++ Name Mangling)

Usingcc,

  1. uncomment static,

[39]   |     68480|      24|FUNC |LOCL |0    |8     |fun

 

  1. comment static,

[49]   |     68504|      24|FUNC |GLOB |0    |8     |fun

 

原创粉丝点击