Skip to main content
2 of 2
added 121 characters in body
Thomas Weller
  • 1.1k
  • 1
  • 9
  • 24

Can I use [[__progmem__]] instead of PROGMEM?

In pgmspace.h, PROGMEM is defined as __ATTR_PROGMEM__, which is defined as __attribute__((__progmem__)). AFAIK, __attribute__ is GNU only. Since C++ 11, we have the attribute specifier sequence.

I can't use [[__progmem__]] instead of PROGMEM. The error is

warning: '__progmem__' attribute directive ignored [-Wattributes]

Shouldn't that work equally?

Why would I want to do that?

  1. Clarity: When I first read code that used PROGMEM, I thought that this is the variable name (being a constant, we have a conding guideline that it should be upper case, which matched). Reading on, I found the real variable name, which confused me. Putting it into square brackets would immediately have made clear that it's an attribute and not a name.
  2. Portability: [[ ]] is Standard C++, whereas __attribute__ is not.
Thomas Weller
  • 1.1k
  • 1
  • 9
  • 24