mofosyne / arduino-gameboy-printer-emulator

Code to emulate a gameboy printer via the gameboy link cable
https://mofosyne.github.io/arduino-gameboy-printer-emulator/
GNU General Public License v3.0
318 stars 41 forks source link

Latest arduino IDE (1.8.7) breaks the arduino sketch #8

Closed mofosyne closed 6 years ago

mofosyne commented 6 years ago

Arduino: 1.8.7 (Mac OS X), Board: "Arduino Nano, ATmega328P"

gbp_emulator:72:15: error: expected unqualified-id before string constant static int serial_putchar(char ch, FILE stream) ^ gbp_emulator:205:15: error: expected unqualified-id before string constant static bool gbp_rx_tx_byte_reset(struct gbp_rx_tx_byte_buffer_t ptr) ^ gbp_emulator:214:15: error: expected unqualified-id before string constant static bool gbp_rx_tx_byte_set(struct gbp_rx_tx_byte_buffer_t ptr, const uint8_t tx_byte) ^ gbp_emulator:219:15: error: expected unqualified-id before string constant static bool gbp_rx_tx_byte_update(struct gbp_rx_tx_byte_buffer_t ptr, uint8_t rx_byte, int rx_bitState) ^ gbp_emulator:338:15: error: expected unqualified-id before string constant static bool gbp_parse_message_reset(struct gbp_packet_parser_t ptr) ^ gbp_emulator:348:15: error: expected unqualified-id before string constant static bool gbp_parse_message_update ^ gbp_emulator:583:15: error: expected unqualified-id before string constant static bool gbp_printer_init(struct gbp_printer_t ptr) ^ exit status 1 expected unqualified-id before string constant

per1234 commented 6 years ago

This is a failure of the Arduino IDE's automatic function prototype generation system. The generated function prototypes look like this:

#line 63 "E:\\gbp_emulator\\gbp_emulator.ino"
static extern "C" int serial_putchar(char ch, FILE* stream);
#line 177 "E:\\gbp_emulator\\gbp_emulator.ino"
 extern "C" void gbp_status_byte_print_as_json_fields(struct gbp_printer_status_t *printer_status_ptr);
#line 196 "E:\\gbp_emulator\\gbp_emulator.ino"
static extern "C" bool gbp_rx_tx_byte_reset(struct gbp_rx_tx_byte_buffer_t *ptr);
#line 205 "E:\\gbp_emulator\\gbp_emulator.ino"
static extern "C" bool gbp_rx_tx_byte_set(struct gbp_rx_tx_byte_buffer_t *ptr, const uint8_t tx_byte);
#line 210 "E:\\gbp_emulator\\gbp_emulator.ino"
static extern "C" bool gbp_rx_tx_byte_update(struct gbp_rx_tx_byte_buffer_t *ptr, uint8_t *rx_byte, int *rx_bitState);
#line 329 "E:\\gbp_emulator\\gbp_emulator.ino"
static extern "C" bool gbp_parse_message_reset(struct gbp_packet_parser_t *ptr);
#line 339 "E:\\gbp_emulator\\gbp_emulator.ino"
static extern "C" bool gbp_parse_message_update( struct gbp_packet_parser_t *ptr, bool *packet_ready_flag, struct gbp_packet_t *packet_ptr, struct gbp_printer_t *printer_ptr, const bool new_rx_byte, const uint8_t rx_byte, bool *new_tx_byte, uint8_t *tx_byte );
#line 574 "E:\\gbp_emulator\\gbp_emulator.ino"
static extern "C" bool gbp_printer_init(struct gbp_printer_t *ptr);
#line 588 "E:\\gbp_emulator\\gbp_emulator.ino"
 extern "C" void serialClock_ISR(void);
#line 661 "E:\\gbp_emulator\\gbp_emulator.ino"
 extern "C" void setup();
#line 706 "E:\\gbp_emulator\\gbp_emulator.ino"
 extern "C" void loop();

Clearly the Arduino IDE didn't take the right action but this error does not occur when using the beta version of the Arduino IDE (which has a new prototype generation system) so it's not necessary to report it to Arduino.

The Arduino IDE only generates function prototypes when none was added to the sketch manually so the problem can be solved by adding the correct prototypes for these functions to the sketch. However, my question is: Is it even useful in any way to wrap the .ino file in extern "c" {} in the first place. If not, then that code should be removed and then it's not necessary to add the prototypes.

mofosyne commented 6 years ago

Thanks, I haven't yet tested personally. But removing the wrap extern "c" {} does make it compile at least.

mofosyne commented 6 years ago

Okay it has been confirmed to work by multiple sources. Now informing everyone that the latest commit fixes the issue.