question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Use of #ifdef not processed consistently

See original GitHub issue

Solutions

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.

Just use the https://github.com/esp8266/Arduino/blob/74819a763bfb6e9890a57411dcea4aba221a778d/libraries/esp8266/examples/Blink/Blink.ino

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:closed
  • Created 4 years ago
  • Comments:22 (7 by maintainers)

github_iconTop GitHub Comments

5reactions
TD-ercommented, Sep 2, 2019

That’s a noble pursuit 😃

1reaction
TD-ercommented, Sep 5, 2019

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)

Read more comments on GitHub >

github_iconTop Results From Across the Web

iphone - #ifdef Condition not working the way that I want it to
I am creating UniversalApp programmatically. in my app i have 2 constant class's and on the basis of device i want to import...
Read more >
Living in the #ifdef Hell - CQSE GmbH
In many systems this mechanism is used to express variations that cannot or should not be handled at runtime. Types of variation include:....
Read more >
Can we use always block inside `ifdef? - Verification Academy
As per the question, you can have always @* inside ifdefs for different functionality, but you cannot define macros based on signal values....
Read more >
What is the #ifdef directive in C? - Educative.io
The #ifdef is one of the widely used directives in C. It allows conditional compilations. During the compilation process, the preprocessor is supposed...
Read more >
The C Preprocessor: Conditionals
Of course, you can only use this to exclude code, not type definitions ... always matches the nearest `#ifdef' (or `#ifndef' , or...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found