Skip to main content
Clarifying which "user" I meant; fixed code thinko/typo.
Source Link
timemage
  • 5.7k
  • 1
  • 15
  • 27

I take this to mean that you do not want to have to ask the user of the code to configure a boolean flag.

The ESP8266 Arduino package provides -DARDUINO_ARCH_ESP8266 -DESP8266 command-line options these while calling g++. These effectively #define feature test macros as though they were at the beginning of the source code.

For ESP32 it does likewise with -DARDUINO_ARCH_ESP32 -DESP32

You could perform tests in your code such as:

#if defARDUINO_ARCH_ESP8266defined (ARDUINO_ARCH_ESP8266)
// do one thing
#elif defined(ESP32)
// do another
#else
#error Architecture unrecognized by this code.
#endif

There are likely also macros like these that are predefined by the xtensa g++ compiler.

I take this to mean that you do not want to have to ask the user to configure a boolean flag.

The ESP8266 Arduino package provides -DARDUINO_ARCH_ESP8266 -DESP8266 command-line options these while calling g++. These effectively #define feature test macros as though they were at the beginning of the source code.

For ESP32 it does likewise with -DARDUINO_ARCH_ESP32 -DESP32

You could perform tests in your code such as:

#if defARDUINO_ARCH_ESP8266)
// do one thing
#elif defined(ESP32)
// do another
#else
#error Architecture unrecognized by this code.
#endif

There are likely also macros like these that are predefined by the xtensa g++ compiler.

I take this to mean that you do not want to have to ask the user of the code to configure a boolean flag.

The ESP8266 Arduino package provides -DARDUINO_ARCH_ESP8266 -DESP8266 command-line options these while calling g++. These effectively #define feature test macros as though they were at the beginning of the source code.

For ESP32 it does likewise with -DARDUINO_ARCH_ESP32 -DESP32

You could perform tests in your code such as:

#if defined (ARDUINO_ARCH_ESP8266)
// do one thing
#elif defined(ESP32)
// do another
#else
#error Architecture unrecognized by this code.
#endif

There are likely also macros like these that are predefined by the xtensa g++ compiler.

Source Link
timemage
  • 5.7k
  • 1
  • 15
  • 27

I take this to mean that you do not want to have to ask the user to configure a boolean flag.

The ESP8266 Arduino package provides -DARDUINO_ARCH_ESP8266 -DESP8266 command-line options these while calling g++. These effectively #define feature test macros as though they were at the beginning of the source code.

For ESP32 it does likewise with -DARDUINO_ARCH_ESP32 -DESP32

You could perform tests in your code such as:

#if defARDUINO_ARCH_ESP8266)
// do one thing
#elif defined(ESP32)
// do another
#else
#error Architecture unrecognized by this code.
#endif

There are likely also macros like these that are predefined by the xtensa g++ compiler.