#if and #elif doesn't work as intended in Cpp

41 Views Asked by At

I am trying to make some sort of easy way to define mcu that I use, and by defining mcu, different header files should be included. I tried doing it with #if and #elif directives :

#include "Parameters.h"

#if MCU_IN_USE == ESP32_S3_MINI_1
   #include "ESP32_S3_MINI_1_PINOUT.h"
#elif MCU_IN_USE == ESP32_S3_WROOM
   #include "ESP32_S3_WROOM_PINOUT.h"
#endif

and in Parameters.h file I defined MCU like this:

//#define MCU_IN_USE         ESP32_S3_MINI_1
#define MCU_IN_USE         ESP32_S3_WROOM

I plan to uncomment the one I use and comment the other one, but the problem is that no matter which define is uncommented, I always get first option in #if statement even though, I am using #elif define: enter image description here

What causes this problem?

1

There are 1 best solutions below

0
Dominykas On

So basically I defined MCU_IN_USE to ESP32_S3_WROOM and ESP32_S3_WROOM is defined to nothing, it is not constant or string or anything, it's just an empty definition. I don't know why I did this, because it super basic mistake, but fixed it by including this

#define ESP32_S3_MINI_1     0
#define ESP32_S3_WROOM      1