I thought I read recently that there is a nicer way to declare and access flash-based data. Did I dream that, misunderstand, or is it true? Didn't find anything with some searches. Thanks.
Is there a replacement for PROGMEM and its access functions?
Didn't find anything with some searches.
The user manual for it:
Thanks, guys, this is SO much nicer! Anybody know when it was added?
As a silly question.
Is there a mechanism for sensible handling of anonymous strings?
Or do you have to continue with the PSTR() abortion?
David.
The problem with PSTR is that pointers to it will point to the generic space (RAM). PSTR locates in flash but that does not change the address space to flash.
If you use a consumer function that uses const __flash* then it will still read from flash and you get the desired behavior.
You can read the Embedded C extension ISO/IEC TR 18037 for the gory details. IMO there are some shortcomings regarding string literals. PSTR should cast the outgoing address to const __flash char* provided the built-in macro __FLASH is defined. PSTR only works locally whereas ((const __flash char[]) { "foo" }) will only work globally.
The compiler can recognise a named literal or an anonymous literal.
CodeVision and ImageCraft handle it very well.
8051 compilers have always put anonymous strings in __code memory.
Yes, I agree that you do occasionally get anomalies. And after many years of wrapping strings with PSTR(), there is no great problem just continuing.
OTOH, I am sure that the whole subject could be handled more elegantly.
David.
Anybody know when it was added?
http://gcc.gnu.org/gcc-4.7/changes.html (search for named)
Better: search for avr to find *all* relevant changes.
PSTR only works locally whereas ((const __flash char[]) { "foo" }) will only work globally.
void foo(void) { static const __flash char bar[] = { "foobar" }; ...
Or did you mean something else?
Consider code like that:
#define FSTR(X) ((const __flash char[]) { X }) const __flash char *pstr = FSTR ("foo");