constexpr in Arduino code?


I'm trying to use constexpr instead of #define to define some byte constants, for example

constexpr uint8_t BUTTON1_BIT = 1 << 2;  // set bit 2 in the mask byte

Problem is, constexpr was only introduced in C++ 2011 standard. constexpr is like const, except that it doesn't take up any space in memory because the value is only used at compile time.

The Arduino IDE works just fine because part of the gcc command line is the switch -std=gnu++11 to enable 2011 support.

Yes, I know, I could use const or use a #define instead but I think constexpr is cleaner. Is there any way to alter the compiler switches?

Thanks in advance


Please sign in to leave a comment.