我遇到了一些遗留代码,它们无法构建在较新的编译器上。该归结例如:针对冲突变量声明的编译器错误:“与具有'C'链接的新声明冲突'
int x;
extern "C" { int x }; // conflicts with C++ linkage above
// note: without the braces it would've been equivalent to:
// extern "C" { extern int x; }
//
// for reference, see the notes section here:
// http://en.cppreference.com/w/cpp/language/language_linkage#notes
老的编译器不下垂,但两者的gcc(如4.1.2)和铛举报。
锵的输出:
error: declaration of 'x' has different language linkage
GCC的输出:
error: previous declaration of 'int x' with 'C++' linkage
error: conflicts with new declaration with 'C' linkage
这让我感到惊讶,因为编译器不以任何特殊的方式裂伤x
,而据我所知没有什么不同关于除调试信息以外的目标文件(基于我公认的使用objdump/readelf进行浅测试)
我的问题:为什么这是一个错误,如果重新没有功能差异?
另外,我并不反对改变代码;我想知道是否有更多的事情不仅仅是“标准说这是不健康的”。
请问为什么downvote? –