检查编译器是否是Turbo C ++

问题描述 投票:3回答:1

我目前正在处理为Turbo C++设计的遗留代码。要解决Turbo C ++缺少bool数据类型的问题,该程序包含以下代码行。

// Necessary when compiling with Turbo C++
enum bool {false, true};

大多数C ++编译器都无法使用error: expected identifier before 'bool'运行程序。虽然我希望切换到更新的编译器,但遗憾的是我需要维护此解决方法以实现向后兼容性。

我怎么能指出这个特定的代码行只能在Turbo C ++中编译?

c++ turbo-c++ predefined-macro
1个回答
4
投票

正如Thomas Matthewsselbie在评论中所建议的那样:

#ifdef __TURBOC__
    // Only runs if compiler is Turbo C++
    enum bool {false, true};
#endif

资料来源:http://beefchunk.com/documentation/lang/c/pre-defined-c/precomp.html

© www.soinside.com 2019 - 2024. All rights reserved.