I have a preloaded const char * table where I want the strings in the table to also be in the PROGMEM. So I changed it to use the F() macro. Since I didn't want this to assign the strings unless I wanted them in program memory, I added the following prolog
#define _progmem_s_ // put constant strings in PROGMEM
#define _progmem_table_ // put the table of translations in PROGMEM
//#define _DEBUG
#ifndef _progmem_s_
#undef F
#define F(x) x
#endif
static const
#ifdef _progmem_table_
PROGMEM
#endif // _progmem_table_
char * const ToMorse[ ] = {
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, // 00-07
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, // 08-0F
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, // 10-17
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, // 18-1F
// sp
F(" "), NULL, NULL, NULL, NULL, NULL, NULL, NULL, // 20-27
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, // 28-2F
//-------------------------------------------------------------------------------------------------------
// 0 1 2 3 4 5 6 7
F("_____"), F(".____"), F("..___"), F("...__"), F("...._"), F("....."), F("_...."), F("__..."), // 30-37 '0'-'7'
//-------------------------------------------------------------------------------------------------------
// 8 9 : ; < = > ?
F("___.."), F("____."), NULL, NULL, NULL, NULL, NULL, NULL, // 38-3F '8', '9'
//-------------------------------------------------------------------------------------------------------
and I get these error messages (just one is shown, but every use of F() gives the same error message)
Compiling sketch...
/Applications/Arduino.app/Contents/Java/hardware/tools/avr/bin/avr-g++ -c -g -Os -Wall -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -Wno-error=narrowing -MMD -flto -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10808 -DARDUINO_AVR_NANO -DARDUINO_ARCH_AVR -I/Applications/Arduino.app/Contents/Java/hardware/arduino/avr/cores/arduino -I/Applications/Arduino.app/Contents/Java/hardware/arduino/avr/variants/eightanaloginputs /var/folders/g2/chzccymj1ll4vnn2pg5v4gfr0000gn/T/arduino_build_928755/sketch/Morse2.ino.cpp -o /var/folders/g2/chzccymj1ll4vnn2pg5v4gfr0000gn/T/arduino_build_928755/sketch/Morse2.ino.cpp.o
In file included from /Applications/Arduino.app/Contents/Java/hardware/arduino/avr/cores/arduino/Arduino.h:28:0,
from /var/folders/g2/chzccymj1ll4vnn2pg5v4gfr0000gn/T/arduino_build_928755/sketch/Morse2.ino.cpp:1:
/Applications/Arduino.app/Contents/Java/hardware/arduino/avr/cores/arduino/WString.h:38:74: error: statement-expressions are not allowed outside functions nor in template-argument lists
#define F(string_literal) (reinterpret_cast<const __FlashStringHelper *>(PSTR(string_literal)))
^
/Users/flounder/Documents/Arduino/Morse2/Morse2.ino:76:4: note: in expansion of macro 'F'
F(" "), NULL, NULL, NULL, NULL, NULL, NULL, NULL, // 20-27
^
/Applications/Arduino.app/Contents/Java/hardware/arduino/avr/cores/arduino/WString.h:38:74: error: statement-expressions are not allowed outside functions nor in template-argument lists
#define F(string_literal) (reinterpret_cast<const __FlashStringHelper *>(PSTR(string_literal)))
^
/Users/flounder/Documents/Arduino/Morse2/Morse2.ino:80:4: note: in expansion of macro 'F'
FYI: Here's the code that fetches the data. It is untested because I can't compile it. (It compiles and works fine when progmem_s is undefined):
#ifdef _progmem_table_
char * target = (char *)pgm_read_word(&ToMorse[ch]);
#else // _progmem_table
char * target = ToMorse[ch];
#endif // _progmem_table_
// ... lots of irrelevant code here
for(uint16_t i = 0; ; ++i)
{
#ifdef _progmem_s_
char Morse = pgm_read_byte(&target[i]);
#else // _progmem_s_
char Morse = target[i];
#endif // _progmem_s_
if(!Send(Morse))
break; // Send returns false when Morse is '\0'
}
EndOfCharacter();
Any suggestions as to what is wrong here, and how I can fix it?