vancegroup/arduino-boost

config/platform/avr.hpp undefs F() macro

Opened this issue · 1 comments

pnd10 commented

In the Arduino WString.h header, the F() macro is defined to allow strings to be put in flash (saving precious SRAM).

At the end of boost/config/platform/avr.hpp is the following snippet:

// Defined by arduino/wiring WString.h
#ifdef F
  #undef F
#endif

This means that the F() macro no longer works, and produces compilation errors:
error: ‘F’ was not declared in this scope
What is the reason for undefining the macro? At the very least, the explicit reason why F() is undefined should be documented, and what to do about it if you need to use the F() macro

I assume the reason is that boost uses F as an identifier (e.g. variable name or template argument) in a ton of places, so keeping it defined will break parsing of all those places. It's a bit annoying that Arduino uses such a short macro, but we'll have to deal with it anyway. One alternative to undeffing the macro is to use the push_macro and pop_macro pragmas, though I'm not sure how portable or future-proof that is (gcc documents "For compatibility with Microsoft Windows compilers, GCC supports ‘#pragma push_macro("macro_name")’"