c++ - 预处理器在评估 `QT_CONFIG(printer)` 时除以零

标签 c++ macros qt5.9

使用 g++(从用 qmake 生成的 Makefile)编译

#if !QT_CONFIG(printer)
    // do something
#endif

在两个 g++ (7.3.0) 上都出现预处理器错误

test.cpp:25:6: error: division by zero in #if
 #if !QT_CONFIG(printer)

和 clang (6.00)

test.cpp:25:6: error: division by zero in preprocessor expression
#if !QT_CONFIG(printer)
     ^~~~~~~~~~~~~~~~~~
/usr/include/x86_64-linux-gnu/qt5/QtCore/qglobal.h:84:30: note: expanded from macro 'QT_CONFIG'
#define QT_CONFIG(feature) (1/QT_FEATURE_##feature == 1)
                            ~^~~~~~~~~~~~~~~~~~~~~
1 error generated.

clang++ 给出了更详细的输出。 printer 未启用,因此建议使用宏进行条件编译。 QT版本为5.9.5。任何建议(错误用法?)表示赞赏。

最佳答案

我认为您不应该专注于该宏。该宏的目的是在 QT_FEATURE_printer 为零时简单地使您的编译代码崩溃。该代码并非旨在以其他方式工作。

不要有条件地使用宏,而是尝试找出 QT_FEATURE_printer 为零的原因并包含/配置依赖项以更改它(它似乎在 printsupport/qtprintsupport-config.h 中定义)。

关于c++ - 预处理器在评估 `QT_CONFIG(printer)` 时除以零,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55823977/

相关文章:

c++ - 使用 VS2010 的 C++ 中的位集(另一个)

可以在串联 ## 宏中替换整型变量吗?

macros - 为什么要尽可能多地删除宏?

qt - g++由qmake使用,gcc由套件配置

ios - 项目错误:此mkspec需要Xcode 4.3或更高版本

c++ - 在 Visual Studio 中调试 PIMPL(2012)

尝试将函数绑定(bind)到 lua 时出现 C++ 错误

c++ - public 和 private 对对象的内存布局有影响吗?

syntax - 制作 "derived"标识符的最简洁方法?