-
-
Notifications
You must be signed in to change notification settings - Fork 403
Generated prototype incorrectly prefixed with extern "C"
when using extern "C" { ... }
to mix C functions in an .ino
file.
#1618
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
Thanks @dmalenic In case it will be useful to the developers, I'll provide a minimal demo of the bug:
Vaguely related to #1591 |
I think this is another case where the automatic prototype generation that arduino-cli does cannot cope with more complicated sketches. What I suspect happens, is that a prototype is generated for the loop() and setup() functions. IIRC prototypes are inserted directly before the first other function definition or declaration found in the .ino file (so they can end up after any initial type declarations when those are before all functions). In this case, that puts the prototypes inside the extern "C" blocks, which leads to conflicting declarations. I'm not sure, but I suspect that this is going to be hard to fix (certainly with the ctags-based approached, but even for the clang-based parsing approach this probably needs some special casing). Also, if you're working with external C functions like this, chances are you're already a more advanced that does not really need the auto-generated prototypes at all. Here's some things you could do/try to get your code working right now:
|
extern "C" { ... }
to mix C functions in an .ino
file.extern "C" { ... }
to mix C functions in an .ino
file.
I've updated the issue title, as this is not an ESP32-specific issue. |
Additional observation, that might be helpful. My original report was I just tried script @per1234 provided and it breaks. But If I load the sketch his script created Hopefully this observation helps, at least with resolving the |
extern "C" { ... }
to mix C functions in an .ino
file.extern "C"
when using extern "C" { ... }
to mix C functions in an .ino
file.
Describe the problem
Compiling the following blink sketch for ESP32 board:
results in errors:
Arduino CLI version
Original report
Arduino IDE 1.8.19
Last verified with
60c1c98
Operating system
Operating system version
Additional context
If the
extern "C" { ... }
block does not define any function but only variables, or if the wholeextern "C" { ... }
block is moved after the definition ofsetup
andloop
functions, the code compiles successfully.If the
extern "C" { ... }
block only declares functions, and functions are defined in a separate module (file), everything compiles correctly.The files with
.cpp
extensions do not have this problem, and allow mixingC
linkage functions defined withinextern "C" { ... }
blocks.Looks like, when the compiler encounters a
C
linkage function definition in a sketch file (.ino
extension), it assumes that the rest of file defines onlyC
linkage functions.The error can not be reproduced when compiling for boards using AVR or ARM processors that I could test with.
Related
extern "C"
when comment contains//
#1591Issue checklist
The text was updated successfully, but these errors were encountered: