Contact me: hankecnc@gmail.com

GRBL 宏被 Arduino.h 重新定义 #766

推推 grbl 3年前 (2023-01-22) 177次浏览

关闭
J-Dunn 打开了这个问题 2015 年 7 月 17 日 · 2 条评论
关闭

GRBL 宏被 Arduino.h 重新定义#766

J-Dunn 打开了这个问题 2015 年 7 月 17 日 · 2 条评论

注释

GRBL 宏被 Arduino.h 重新定义 #766

我刚刚使用 -Wall(“IDE”中的详细选项)构建了 GRBL,并注意到有关某些宏被重新定义的多个警告。我没有看到“最大”情况下的任何差异,但位测试可能在 nutbolt.h 中被重写以提高效率,但由于在编译期间读取内容的顺序,原始定义似乎是被使用的定义。

由于“位”宏在核心 ISR 中多次使用,因此按预期进行这项工作可能是值得的。

In file included from grbl_sketch.ino:29:0:
/usr/share/arduino/hardware/arduino/cores/arduino/Arduino.h:65:0: warning: "max" redefined
 #define max(a,b) ((a)>(b)?(a):(b))
 ^
In file included from /svn/stm32/avr/wkg/libraries/grbl/system.h:41:0,
                 from grbl_sketch.ino:4:
/svn/stm32/avr/wkg/libraries/grbl/nuts_bolts.h:48:0: note: this is the location of the previous definition
 #define max(a,b) (((a) > (b)) ? (a) : (b))
 ^
In file included from grbl_sketch.ino:29:0:
/usr/share/arduino/hardware/arduino/cores/arduino/Arduino.h:91:0: warning: "bit" redefined
 #define bit(b) (1UL << (b))
 ^
In file included from /svn/stm32/avr/wkg/libraries/grbl/system.h:41:0,
                 from grbl_sketch.ino:4:
/svn/stm32/avr/wkg/libraries/grbl/nuts_bolts.h:52:0: note: this is the location of the previous definition
 #define bit(n) (1 << n) 
 ^
GRBL 宏被 Arduino.h 重新定义 #766
作者

仔细观察一下,nutsbolts.h 中的 bit(n) 宏被 GRBL 库中的几个 .c 文件使用。这似乎至少在将 arduino.h 添加到源文件以访问一些库定义的常量时可能不稳定。

从警告来看,似乎有几个实例,其中较长的 arduino.h 宏被扩展到可能是较短的 GRBL 的地方。

在编译器都可以访问的上下文中重复使用宏的名称似乎是不必要的风险或引发细微的错误。尽管在这种情况下,它可能只会有点低效。

我将重命名 nutsbolts 版本 bit16(n)

从 -Wall 输出中去除所有这些杂物以使其更具可读性也很好。

GRBL 宏被 Arduino.h 重新定义 #766
作者

糟糕,我的错。我不必要地包含了 Arduino.h。
Arduino.h 似乎确实被添加到草图中,但这会导致一个重新定义警告。
关闭。

喜欢 (0)