能否通过 编译器设置 或其它方法 屏蔽或消除 MS VC C1045 错误?
环境:Windows XP SP2, VC2005 SP1
问题详述:
使用C语言模式编译下面示例代码,没有问题。
使用C++模式编译下面示例代码,出现C1045问题:
Microsoft Visual Studio8\VC\include\sal.h(226):fatal error C1045: compiler limit: linkage specifications nested too deeply
代码示例:
#ifdef __cplusplus
extern "C" {
#endif
#ifdef __cplusplus
extern "C" {
#endif
#ifdef __cplusplus
extern "C" {
#endif
#ifdef __cplusplus
extern "C" {
#endif
#ifdef __cplusplus
extern "C" {
#endif
#ifdef __cplusplus
extern "C" {
#endif
#ifdef __cplusplus
extern "C" {
#endif
#ifdef __cplusplus
extern "C" {
#endif
#ifdef __cplusplus
extern "C" {
#endif
#include <stdio.h>
#ifdef __cplusplus
}
#endif
#ifdef __cplusplus
}
#endif
#ifdef __cplusplus
}
#endif
#ifdef __cplusplus
}
#endif
#ifdef __cplusplus
}
#endif
#ifdef __cplusplus
}
#endif
#ifdef __cplusplus
}
#endif
#ifdef __cplusplus
}
#endif
#ifdef __cplusplus
}
#endif
int main()
{
return 0;
}
错误描述已经给个够清楚,当extern嵌套层数超过9层时,在C++模式下即会出现这种错误。
上面示例代码实际上是大规模头文件嵌套后造成的,但由于代码属于大规模遗留系统,实际上没有能力对上面代码进行整改;所以问题就变为:
是否可以不修改上面的示例代码,而是比如通过修改编译器设置,或者在这代码外围加上一些其它代码,让上面这段代码在C++模式下编译通过?如果可以?如何修改?
PS:
VC6/2005下不可以undef编译器内置宏__cplusplus(但gcc可以)。