Skip to content

#include "arduino.h" being added in inconsistent places #248

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
per1234 opened this issue Sep 14, 2017 · 6 comments
Closed

#include "arduino.h" being added in inconsistent places #248

per1234 opened this issue Sep 14, 2017 · 6 comments
Labels
status: waiting for information More information must be provided before work can proceed topic: code Related to content of the project itself topic: preprocessor Related to sketch preprocessing type: imperfection Perceived defect in any part of project

Comments

@per1234
Copy link
Contributor

per1234 commented Sep 14, 2017

Imported from arduino/Arduino#6721

@ianahner wrote:

I do not have time to chase this issue at the moment, but if I find time I will try to track down the cause and append more info. The issue is this:

Different computers have proven to be inconsistent in where they put the #include arduino.h line.

It is always before setup loop, which is good, but in an example today there was an issue.

I was supporting two different hardware designs, one using software serial and one using hardware serial. There was therefore the following code above the setup loop:

sudo code:

#ifdef IS_DESIGN_1
  //declare software serial
#endif

The arduino IDE chose to add the include in the middle so that the following occurred:

#ifdef IS_DESIGN_1
  //declare software serial
  #include "arduino.h"
#endif

Due to the fact that the design 1 bit didn't currently apply, the compiler missed the include and spit out a bunch of errors. The problem was resolved by manually including arduino.h, but looking in the tmp file that was generated, I can see that it was still ALSO included inside the #ifdef. This code should be reviewed to avoid this.

I will work on it if I have time, but meanwhile if anyone more familiar with the way the arduino ide build system functions, perhaps you could guess at why this is happening. I do not think it is unreasonable for #ifdef to exist in the header of a file. I know that is not typical of arduino, but in the embedded world where I typically work that is fairly standard practice.

@per1234
Copy link
Contributor Author

per1234 commented Sep 14, 2017

Which version of the Arduino IDE are you using on each computer?

@per1234
Copy link
Contributor Author

per1234 commented Sep 14, 2017

@ianahner wrote:

1.8.4 on both computers. Linux on one machine, Windows 10 on the other.

The Windows 10 machine was ultimately the one that had the issue, though both seem to be fairly arbitrary in their placement.

@per1234
Copy link
Contributor Author

per1234 commented Sep 14, 2017

Please provide a minimal complete sketch that we can use to reproduce the issue.

@ianahner
Copy link

I will try to build a sketch and tweak it until I can reliably land the #include inside a #ifdef...

The computer that was doing it is at work, so no joy until I'm back there.

Perhaps though we could look at something as simple as always adding that at the first line?

Without me digging around for days, does anyone know which bit of code handles that insertion?

I will try to get a reproducible chunk of code when I'm back at work.

@matthijskooijman
Copy link
Collaborator

What's weird is that IIRC builder preprocesses the file first, and then decides based on the result where to insert the Arduino.h include and function prototypes (using the preprocessor annotations to backreference to the original line numbers). Though perhaps this applies only to function prototypes and not Arduino.h perhaps...

@rsora rsora added the status: waiting for information More information must be provided before work can proceed label Sep 22, 2021
@per1234 per1234 added topic: code Related to content of the project itself topic: preprocessor Related to sketch preprocessing type: imperfection Perceived defect in any part of project labels Oct 14, 2021
@per1234
Copy link
Contributor Author

per1234 commented Oct 14, 2021

Closing as probably resolved. It will not be possible to verify due to not having sufficient information to reproduce the original issue.

If anyone is still having this type of issue with the latest version of arduino-builder/Arduino IDE and can provide a minimal reproducible example, please comment here and we'll investigate.

@per1234 per1234 closed this as completed Oct 14, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: waiting for information More information must be provided before work can proceed topic: code Related to content of the project itself topic: preprocessor Related to sketch preprocessing type: imperfection Perceived defect in any part of project
Projects
None yet
Development

No branches or pull requests

6 participants