From 78c05c826c772490e7d2462ac6870bac84d56f98 Mon Sep 17 00:00:00 2001 From: Vincent Pelletier Date: Mon, 31 Oct 2022 08:03:31 +0000 Subject: [PATCH] Cart_Reader.ino: Move definitions after all forward declarations It seems the Arduino IDE picks the position of the first definition to insert all auto-generated forward declarations. This fails to compile if any of these generated forward declarations references a type included later. So, reorder the code a bit so the first definition happens strictly after the last inclusion. --- Cart_Reader/Cart_Reader.ino | 36 ++++++++++++++++++++---------------- 1 file changed, 20 insertions(+), 16 deletions(-) diff --git a/Cart_Reader/Cart_Reader.ino b/Cart_Reader/Cart_Reader.ino index 91a1acc..af0ebc3 100644 --- a/Cart_Reader/Cart_Reader.ino +++ b/Cart_Reader/Cart_Reader.ino @@ -224,22 +224,6 @@ boolean dont_log = false; template int EEPROM_writeAnything(int ee, const T& value); template int EEPROM_readAnything(int ee, T& value); -template int EEPROM_writeAnything(int ee, const T& value) { - const byte* p = (const byte*)(const void*)&value; - unsigned int i; - for (i = 0; i < sizeof(value); i++) - EEPROM.write(ee++, *p++); - return i; -} - -template int EEPROM_readAnything(int ee, T& value) { - byte* p = (byte*)(void*)&value; - unsigned int i; - for (i = 0; i < sizeof(value); i++) - *p++ = EEPROM.read(ee++); - return i; -} - // Graphic SPI LCD #ifdef enable_LCD #include @@ -302,6 +286,26 @@ void _print_FatalError(void) __attribute__((noreturn)); void print_FatalError(const __FlashStringHelper* errorMessage) __attribute__((noreturn)); void print_FatalError(byte errorMessage) __attribute__((noreturn)); +/****************************************** + End of inclusions and forward declarations + *****************************************/ + +template int EEPROM_writeAnything(int ee, const T& value) { + const byte* p = (const byte*)(const void*)&value; + unsigned int i; + for (i = 0; i < sizeof(value); i++) + EEPROM.write(ee++, *p++); + return i; +} + +template int EEPROM_readAnything(int ee, T& value) { + byte* p = (byte*)(void*)&value; + unsigned int i; + for (i = 0; i < sizeof(value); i++) + *p++ = EEPROM.read(ee++); + return i; +} + /****************************************** Common Strings *****************************************/