-
-
Notifications
You must be signed in to change notification settings - Fork 420
Description
Describe the problem
A stray curly-brace in //
comments or #if (false)
sections causes the function prototypes generated during the "sketch pre-processing" stage of the compilation operation to be incorrectly prefixed with extern "C"
For example:
extern "C" void setup();
To reproduce
Compile the following sketch:
#if (false) // The below lines should not be enabled, and so should not have any effect
#error "Should not get to here"
// { // either delete this line,
// extern "C" {} // or delete this line, and the below code is compiled fine!
#endif
void setup() {
Serial.begin(74880);
}
void loop() {
delay(5000);
Serial.println("Hello");
}
Examine the .cpp
file generated by the compilation.
🐛 Generated function prototypes are prefixed with extern "C"
Compile the following sketch:
#if (false) // The below lines should not be enabled, and so should not have any effect
#error "Should not get to here"
// { // either delete this line,
// extern "C" {} // or delete this line, and the below code works fine!
#endif
ADC_MODE(ADC_VCC);
void setup() {
Serial.begin(74880);
}
void loop() {
delay(5000);
Serial.print("raw_battery (should be between 3000 and 3300)="); Serial.println(ESP.getVcc());
// unless you DELETE one of the above two COMMENT lines, you will get "=65535" and not "=3017"
}
Examine the .cpp
file generated by the compilation.
🐛 Generated function prototypes are prefixed with extern "C"
Expected behavior
Generated function prototypes should be correct regardless of the contents of comments:
void setup();
Arduino CLI version
Original report
Arduino IDE v1.8.16
Last verified with
Operating system
Windows
Operating system version
11
Additional context
I note that there are several discussions regarding curly-braces for Arduino IDE but none of these seem to cover this specific issue:
- https://forum.arduino.cc/t/ide-bug-with-braces-that-arent-part-of-the-code/206063
- https://forum.arduino.cc/t/curly-braces-in-strings-or-quotes/212575
Additional reports
Related
Issue checklist
- I searched for previous reports inI verified the problem still occurs when using theMy report contains all necessary detailsTo pick up a draggable item, press the space bar. While dragging, use the arrow keys to move the item. Press space again to drop the item in its new position, or press escape to cancel.
Activity
per1234 commentedon Dec 16, 2021
Thanks @Rob58329!
In case it will be useful to the developers, I'll provide a minimal demo of the bug:
Note that the generated
setup
andloop
function prototypes unexpectedly are prefixed byextern "C"
Preprocessed sketch is as expected after removing the first comment from the sketch:
extern "C"
when usingextern "C" { ... }
to mix C functions in an.ino
file. #1618[-]Arduino-IDE not ignoring stray { curly-braces in “//” comments and “#if (false)” sections when doing the “.ino to .cpp conversion”[/-][+]Generated prototype incorrectly prefixed with `extern "C"` when comment contains `//`[/+].ino
file #2946