相关疑难解决方法(0)

#if中使用的未定义常量的值是多少?

为了评估#if条件,我的预处理器似乎假设未定义的常量为0 .

可以依赖它,还是未定义的常量给出未定义的行为?

c++ c-preprocessor

61
推荐指数
2
解决办法
7521
查看次数

预处理器检查是否未定义多个定义

我在用户可编辑的标题中选择了#define,因此我随后希望检查定义是否存在以防用户完全删除它们,例如

#if defined MANUF && defined SERIAL && defined MODEL
    // All defined OK so do nothing
#else
    #error "User is stoopid!"
#endif
Run Code Online (Sandbox Code Playgroud)

这完全没问题,我想知道是否有更好的方法来检查是否有多个定义没有到位...即:

#ifn defined MANUF || defined SERIAL ||.... // note the n in #ifn
Run Code Online (Sandbox Code Playgroud)

或者可能

#if !defined MANUF || !defined SERIAL ||....
Run Code Online (Sandbox Code Playgroud)

删除空#if部分的需要.

c c-preprocessor

58
推荐指数
2
解决办法
9万
查看次数

标签 统计

c-preprocessor ×2

c ×1

c++ ×1