Skip to content
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

Fix including "Arduino.h" from C files #163

Merged
merged 1 commit into from
Jun 15, 2022

Conversation

guberti
Copy link
Contributor

@guberti guberti commented Jun 8, 2022

Consider the following sketch, to be run on the Portenta H7. We have a project.ino file with the following:

#include "extra.c"

void setup() {}

void loop() {
  blink();
}

We also have an extra.c file in the sketch folder with the following:

#include "Arduino.h"

void blink() {
  digitalWrite(LED_BUILTIN, HIGH);
  delay(250);
  digitalWrite(LED_BUILTIN, LOW);

  delay(250);
}

You can download the zipped sketch here.


This is a valid sketch, and it compiles on most boards (the Arduino Uno, the Nano 33 BLE, the Arduino Due, etc). On the Portenta, however, we get the following error:

In file included from /home/guberti/.arduino15/packages/arduino/hardware/mbed_portenta/3.1.1/variants/PORTENTA_H7_M7/pinmode_arduino.h:30:0,
                 from /home/guberti/.arduino15/packages/arduino/hardware/mbed_portenta/3.1.1/cores/arduino/Arduino.h:26,
                 from /home/guberti/Arduino/demo-portenta-issue/extra.c:1:
/home/guberti/.arduino15/packages/arduino/hardware/mbed_portenta/3.1.1/cores/arduino/api/Common.h:76:9: error: unknown type name 'bool'
 typedef bool      boolean;
         ^~~~
exit status 1
Error compiling for board Arduino Portenta H7 (M7 core).

This occurs because we do not include stdbool.h. We could fix the issue by removing the typedef bool boolean; (it is not used, and the comment suggests someone has been considering it for a while), but just adding the include seems safer.

This PR fixes the issue by adding #include <stdbool.h> at the top of api/Common.h.

@codecov-commenter
Copy link

Codecov Report

Merging #163 (3a6537e) into master (e03b653) will not change coverage.
The diff coverage is n/a.

@@           Coverage Diff           @@
##           master     #163   +/-   ##
=======================================
  Coverage   96.00%   96.00%           
=======================================
  Files          13       13           
  Lines         827      827           
=======================================
  Hits          794      794           
  Misses         33       33           
Impacted Files Coverage Δ
api/Common.h 100.00% <ø> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update e03b653...3a6537e. Read the comment docs.

@guberti
Copy link
Contributor Author

guberti commented Jun 14, 2022

Would love a look from @facchinm!

@facchinm
Copy link
Member

LGTM! Thanks for the patch 😉

@facchinm facchinm merged commit 5f107eb into arduino:master Jun 15, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants