Multi module access of FlashStringTable array

Hi,

I'm using the FlashStringTable C api and it's great because it makes a nice compact area for strings, and later on, I can translate them to another language.

https://www.arduino.cc/reference/en/libraries/flashstringtable/

I have a PlatformIO project with several modules.

But I've got brain fog about how to access this array from another module in the project. I'd normally use extern xxx, but the macros used by FlashStringTable to get the strings into PROGMEM are rather complex.

Does anyone have any ideas?

Many thanks!

Writing the above helped me answer my own question! If the array is declared in a specific C module as:

BEGIN_FLASH_STRING_TABLE(mainStrs)
ADD_FLASH_STRING("atest")
ADD_FLASH_STRING("btest")
END_FLASH_STRING_TABLE()

//access functions:
const __FlashStringHelper* GetFSH(int i)
{
return mainStrs[i];
}

void    InitFST() 
{ 
INIT_FLASH_STRING_TABLE(mainStrs); 
}

Then it's easy to access from outside, simply by including the header and then accessing the two functions, as appropriate.

Serial.print(GetFSH(IDS_ITEMA)); // where IDS_ITEMA is the #defined subscript

I've posted this just in case it's useful for others :grinning:

P.S. One thing that would be great with the FlashStringTable would be to be able to associate an integer value with each string. That would obviate the need to keep a separate set of #defines alongside...

That's often the case :wink:

You can click the solution checkbox under the most useful reply to indicate that the topic is solved so others that experience the same problem know that a solution is provided.