-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Compiler not ignoring stray { curly-braces in “//” comments and “#if (false)” sections #8401
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
Comments
This is an https://github.com/arduino/arduino-cli problem though? It is my understanding that it handles the .ino -> .cpp conversion and causes the issue described here (at least in the recent IDE versions). Note that you can add a separate .ino -> .cpp conversion results can be seen after enabling verbose mode in the IDE logs and opening the temporary directory location. Or, by manually building with 8401.ino.cpp with the code above, .ino -> .cpp erroneously adds extern "C" to everything below the comments #include <Arduino.h>
#line 1 "C:\\Users\\maxim\\Documents\\Arduino\\esp8266-test\\8401\\8401.ino"
#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
#line 7 "C:\\Users\\maxim\\Documents\\Arduino\\esp8266-test\\8401\\8401.ino"
extern "C" int __get_adc_mode(void);
#line 9 "C:\\Users\\maxim\\Documents\\Arduino\\esp8266-test\\8401\\8401.ino"
extern "C" void setup();
#line 13 "C:\\Users\\maxim\\Documents\\Arduino\\esp8266-test\\8401\\8401.ino"
extern "C" void loop();
#line 7 "C:\\Users\\maxim\\Documents\\Arduino\\esp8266-test\\8401\\8401.ino"
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"
} Otherwise, it works as expected #include <Arduino.h>
#line 1 "C:\\Users\\maxim\\Documents\\Arduino\\esp8266-test\\8401\\8401.ino"
#if (false) // The below lines should not be enabled, and so should not have any effect
#error "Should not get to here"
#endif
#line 5 "C:\\Users\\maxim\\Documents\\Arduino\\esp8266-test\\8401\\8401.ino"
int __get_adc_mode(void);
#line 7 "C:\\Users\\maxim\\Documents\\Arduino\\esp8266-test\\8401\\8401.ino"
void setup();
#line 11 "C:\\Users\\maxim\\Documents\\Arduino\\esp8266-test\\8401\\8401.ino"
void loop();
#line 5 "C:\\Users\\maxim\\Documents\\Arduino\\esp8266-test\\8401\\8401.ino"
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"
} |
@mcspr: Very many thanks for your above comments! The “arduino_build_xxx/sketch/yyy.cpp” temporary file is very usefull in finding these stray curly-brackets - thank you! I have now submitted this issue as arduino/arduino-cli#1591, and it will be interesting to see if they can do anything about it! |
Basic Infos
Platform
Settings in IDE
Problem Description
Compiler not ignoring stray { curly-braces in “//” comments and “#if (false)” sections.
I have had issues with the above on a number of different projects over the past few years. Basically even though a sketch compiles without warnings, an update for a project will stop it working, and it will take some time to find out it is a stray curly-brace in a comment somewhere which is causing the issue.
The below sketch demonstrates this issue. As included below it will give the incorrect 65535 when run, but DELETE either of the two comment lines, and it will give the correct approx 3000 when run.
(The D1mini has a voltage divider on the A0 pin, which includes a resistor from A0 to ground, which will cause the above 3000 result to be lower than the real approx 3300 you get with a generic board, however it still demonstrates the issue OK.}
I note that there are several discussions regarding curly-braces for the Arduino-IDE (eg. https://forum.arduino.cc/t/curly-braces-in-strings-or-quotes/212575 )
I also note that in the Arduino-IDE, the “control-T” function USED to include/notice curly-braces in comments and format the sketch including them, making them easier to spot. But sadly this changed a number of years ago, so “control-T” now ignores curly-brackets in comments, and so no longer helps in finding curly-braces buried in comments!
As this would seem to be a compiler "feature", I am unsure if anything can be done about it, but thought I would raise it as an issue just in case!
The text was updated successfully, but these errors were encountered: