How do you do forward declarations in arduino code?

2.5k views Asked by At

I am trying to compile the polargraph code for arduino that someone else wrote. As far as I know the code itself is correct and after I add in the libraries needed to run it I get this error message.

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.

I have heard that you need to set up a forward declaration because it uses two words in its data type and the official arduino compiler doesn't handle that well. How do I go bout doing that?

3

There are 3 answers

0
snoble On BEST ANSWER

The repo for that project has been updated since the zip bundle was made.

The line now reads:

const uint32_t PROGMEM crc_table[16] = {

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

This change was required when Arduino IDE 1.6 came about and broke a bunch of new things!

I have since updated the code bundle to include:

  • crc_table definition fix
  • UTFT library update to v2.81 (for same reason - Arduino IDE 1.6 compatibility)

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

1
Marcus Müller On

That looks like you're coding in simple C; in that case, it's a simple C forward declaration, for example:

struct b;
0
swmcdonnell On

There are two errors showing in what you provided. First, there's no declaration for prog_uint32_t included in the header files for some reason. So you probably need to add:

typedef uint32_t PROGMEM prog_uint32_t;

or include the right header files if anything else is missing.

You have to publish the code for the util.ino sketch to get help on the second error.