Generated function prototype injected before declaration of custom parameter type #2696
Open
3 tasks done
Labels
topic: build-process
Related to the sketch build process
topic: code
Related to content of the project itself
type: imperfection
Perceived defect in any part of project
Describe the problem
In order to make it easier for beginners to get started with writing Arduino sketches, and for the convenience of all users, Arduino CLI automatically generates and adds prototypes for functions defined in a
.ino
file of a sketch.Under certain specific conditions, the function prototype is inserted into the code at a location before the declaration of a custom type referenced in the function signature.
🐛 The sketch compilation fails spuriously.
To reproduce
Setup environment
Demo
🐛 There was a spurious compilation failure of valid code.
By looking at the C++ code generated by the Arduino sketch preprocessor, we can see the cause of the error:
🐛 The spurious compilation failure was caused by Arduino CLI placing the prototype for the
baz
function before the declaration of thebar_t
type.Expected behavior
Generated function prototypes should be inserted after the declarations of types used in the function signature.
Arduino CLI version
Original report
Arduino IDE 1.8.13
Last verified with
c5812ee
Operating system
Operating system version
Additional context
Originally reported at https://forum.arduino.cc/t/weird-g-error-compiling-simple-type-definition/680759
Additional reports
Related
extern "C"
when comment contains//
#1591extern "C"
when usingextern "C" { ... }
to mix C functions in an.ino
file. #1618Workaround
Manually add a function prototype at the appropriate location:
Issue checklist
The text was updated successfully, but these errors were encountered: