你如何在arduino代码中做前向声明?

How do you do forward declarations in arduino code?

我正在尝试为 arduino 编译其他人编写的 polargraph 代码。据我所知,代码本身是正确的,在我添加 运行 所需的库后,我收到此错误消息。

polargraph_server_polarshield.ino:109:16: error: 'prog_uint32_t' does not name a type
In file included from /Applications/Arduino.app/Contents/Resources/Java/hardware/arduino/avr/cores/arduino/Arduino.h:28:0, from /Applications/Arduino.app/Contents/Resources/Java/hardware/arduino/avr/libraries/SPI/SPI.h:17, from polargraph_server_polarshield.ino:47:
util.ino: In function 'long unsigned int crc_update(long unsigned int, byte)':
util.ino:392:31: error: 'crc_table' was not declared in this scope
util.ino:394:31: error: 'crc_table' was not declared in this scope
Error compiling.

我听说您需要设置前向声明,因为它在其数据类型中使用了两个词,而官方的 arduino 编译器处理得不好。我该怎么做?

您似乎是在用简单的 C 语言编写代码;在那种情况下,它是一个简单的 C 前向声明,例如:

struct b;

您提供的内容中有两个错误。首先,由于某种原因,头文件中没有包含 prog_uint32_t 的声明。所以你可能需要添加:

typedef uint32_t PROGMEM prog_uint32_t;

或者如果缺少任何其他内容,请包括正确的头文件。

您必须发布 util.ino sketch 的代码才能获得有关第二个错误的帮助。

该项目的回购已在制作 zip 包后更新。

该行现在显示为:

const uint32_t PROGMEM crc_table[16] = {

(https://github.com/euphy/polargraph_server_polarshield/blob/master/polargraph_server_polarshield.ino#L108)

当 Arduino IDE 1.6 出现并打破了一堆新东西时,需要进行此更改!

我已经更新了代码包以包括:

  • crc_table定义修正
  • UTFT 库更新到 v2.81(出于同样的原因 - Arduino IDE 1.6 兼容性)

(https://github.com/euphy/polargraphcontroller/releases/tag/2015-07-15-21-25)