【问题标题】:Check if compiler is Turbo C++检查编译器是否为 Turbo C++
【发布时间】:2016-11-12 19:40:21
【问题描述】:

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

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

大多数 C++ 编译器无法运行带有error: expected identifier before 'bool' 的程序。虽然我很想切换到更新的编译器,但不幸的是,我需要维护这种解决方法以实现向后兼容性。

我怎样才能表明这行代码只能在 Turbo C++ 中编译?

【问题讨论】:

  • 查找预定义宏,例如__TURBOC__。当 Borland C++ 出现时,我摆脱了 Turbo C++,然后在 2008 年左右放弃了它。你应该使用更新和免费的东西。
  • 你可能想要__TURBOC__,这里建议:beefchunk.com/documentation/lang/c/pre-defined-c/precomp.html
  • 只是好奇,谁还在使用 Turbo C/C++?嵌入式设备?仍在运行 DOS 的旧设备?
  • 大多数嵌入式设备使用其他专业编译器:Keil、Greenhills、IAR、Microsoft、ARM、Intel 和 Gnu。 TurboC++ 不支持嵌入式系统中使用的 ARM Cortex 等现代处理器。
  • @BasileStarynkevitch 我拒绝使用 Turbo C++ 是我需要这项检查的原因。它让我在使用任何现代编译器时都可以忽略教授的 hacky-workaround。

标签: c++ turbo-c++ predefined-macro


【解决方案1】:

根据 cmets 中的 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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-05-15
    • 2017-03-22
    • 1970-01-01
    • 2017-04-21
    • 2019-05-10
    • 2013-11-13
    相关资源
    最近更新 更多