#include <stdio.h>
namespace myname{
double var = 42;
}
extern "C" double _ZN6myname3varE = 10.0;
int main(){
printf("%d\n", _ZN6myname3varE);
return 0;
}
gcc
编译结果为:
Jim@ubuntu:~/workspace/vi_edit$ g++ testSymble.cpp -o testSymble
testSymble.cpp:7:19: warning: ‘_ZN6myname3varE’ initialized and declared ‘extern’ [enabled by default]
testSymble.cpp: In function ‘int main()’:
testSymble.cpp:10:32: warning: format ‘%d’ expects argument of type ‘int’, but argument 2 has type ‘double’ [-Wformat]
/tmp/cczIjRfH.s: Assembler messages:
/tmp/cczIjRfH.s:14: Error: symbol `_ZN6myname3varE' is already defined
为什么_ZN6myname3varE
要重新定义?
警告‘_ZN6myname3varE’ initialized and declared ‘extern’ [enabled by default]
是什么意思?
如果程序在保留名称的上下文中声明或定义名称,则该行为未定义。
17.4.3.1.2 全局名称
每个包含双下划线 (_ _) 或以下划线后跟大写字母 (2.11) 的名称都保留给实现以供任何使用。