gpt4 book ai didi

c - 预处理器平等测试,这是标准吗?

转载 作者:太空狗 更新时间:2023-10-29 16:34:40 26 4
gpt4 key购买 nike

我在项目首选项中设想了其中之一

  • 测试 = 主机
  • 测试 = 目标
  • TESTING 根本没有定义

我的问题是后者。

好像不是

#if TESTING==HOST
#error "HOST defined" // add temporarilly for testing porpoises
#endif

我需要编码

#ifdef TESTING   
#if TESTING==HOST
#error "HOST defined" // add temporarilly for testing porpoises
#endif
#endif

我确信这不是标准行为,因为如果未定义 TESTING 那么它肯定不等于 HOST,我不需要额外的#ifdef TESTING 使用 GCC 编译器。

但是,当我使用 Atmel AVR Studio(我认为是基于 MS Visual Studio)时,有必要在几十个地方:-(

看起来我别无选择,但我只是想知道是否有任何 C 标准确实需要这个。

最佳答案

#if TESTING==HOST

如果未定义TESTING,则

相当于:

#if 0==HOST

来自 C 标准:

(C99, 6.10.1p4) "After all replacements due to macro expansion and the defined unary operator have been performed, all remaining identifiers (including those lexically identical to keywords) are replaced with the pp-number 0""

关于c - 预处理器平等测试,这是标准吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13149189/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com