Use of #ifdef not processed consistently
See original GitHub issueSolutions
1. Convert INO files to CPP
2. Manual prototype declaration
#ifdef DO_NOT_USE
typedef int32_t delaytype;
void thisShouldNotAppearInTheBinary(delaytype timer); // aded manually
void thisShouldNotAppearInTheBinary(delaytype timer) {
delay(timer);
}
#endif
PlatformIO Core. As discussed here: https://github.com/esp8266/Arduino/issues/6475
Configuration
Operating system: Windows & Linux
PlatformIO Version (platformio --version
):
PlatformIO, version 4.0.3
Description of problem
When generating forward declarations of functions in the <project>.ino.cpp, the wrapping #ifdef statements are not taken into account.
Steps to Reproduce
Simple steps to reproduce: https://github.com/esp8266/Arduino/issues/6475#issuecomment-527077618
Not really a very simple project at hand here, but I guess this should be enough to have in the project.ino file.
and add some function like this in the .ino file:
#ifdef DO_NOT_USE
void thisShouldNotAppearInTheBinary() {
delay(1000);
}
#endif
As long as you don’t have the DO_NOT_USE
flag set, you should not see it in the generated .ino.cpp file. (it should be wrapped in the #ifdef statements)
Well at least, that’s what I expect should happen.
Things will fail to build if you have some object used as parameter which is only defined when a flag is set. For example:
#ifdef DO_NOT_USE
typedef int32_t delaytype;
void thisShouldNotAppearInTheBinary(delaytype timer) {
delay(timer);
}
#endif
Issue Analytics
- State:
- Created 4 years ago
- Comments:22 (7 by maintainers)
That’s a noble pursuit 😃
Thanks for the reply. I already found out what was happening. Maybe I should apply my own rule-of-thumb to posting replies like these as with merging commits… Don’t do it after midnight 😉
“global” variables in a .h file will indeed lead to multiple declarations from where they are included. If you really want to make them shared, the objects should either be static (not static declare in the .h!!), or I could create a single “global vars” object, which does include all these and get/set functions to access either the “global vars” object or for many separate objects.
So last night’s reply was kind of a frustration caused by a PEBKAC 😃 (and lack of sleep by then)