That is because it is a completely different bug and so off topic for the report of the "Generated function prototype injected before declaration of custom parameter type" bug.
I created a dedicated issue for the bug reported in this topic:
opened 08:52PM - 02 Sep 24 UTC
type: imperfection
topic: build-process
### Describe the problem
In order to make it easier for beginners to get starโฆ ted 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](https://arduino.github.io/arduino-cli/dev/sketch-build-process/#pre-processing).
[Attributes](https://gcc.gnu.org/onlinedocs/gcc/Function-Attributes.html) can be used to specify properties of a function. The attribute declaration may be placed at a variety of locations relative to a function definition.
๐ A prototype is not generated for the function if the attribute declaration is placed between the type and name in the function definition.
### To reproduce
#### Setup environment
```text
$ arduino-cli version
arduino-cli Version: git-snapshot Commit: c5812eea6 Date: 2024-09-02T17:16:38Z
$ mkdir -P "/tmp/FooSketch"
$ printf '
void loop() {}
void setup() {
foo();
}
void __attribute__(()) foo() {}
' > "/tmp/FooSketch/FooSketch.ino"
```
#### Demo
```text
$ arduino-cli compile --fqbn arduino:avr:uno "/tmp/FooSketch"
C:\Users\per\AppData\Local\Temp\FooSketch\FooSketch.ino: In function 'void setup()':
C:\Users\per\AppData\Local\Temp\FooSketch\FooSketch.ino:3:3: error: 'foo' was not declared in this scope
foo();
^~~
```
๐ The compilation failed unexpectedly.
By looking at the C++ code generated by the Arduino sketch preprocessor, we can see the cause of the error:
```text
$ arduino-cli compile --fqbn arduino:avr:uno --preprocess "/tmp/FooSketch"
#include <Arduino.h>
#line 1 "C:\\Users\\per\\AppData\\Local\\Temp\\FooSketch\\FooSketch.ino"
#line 1 "C:\\Users\\per\\AppData\\Local\\Temp\\FooSketch\\FooSketch.ino"
void loop();
#line 2 "C:\\Users\\per\\AppData\\Local\\Temp\\FooSketch\\FooSketch.ino"
void setup();
#line 1 "C:\\Users\\per\\AppData\\Local\\Temp\\FooSketch\\FooSketch.ino"
void loop() {}
void setup() {
foo();
}
void __attribute__(()) foo() {}
```
๐ The compilation failure was caused by Arduino CLI not creating a prototype for the `foo` function.
### Expected behavior
Prototypes are generated for functions with attribute declarations between the type and name.
### Arduino CLI version
c5812eea68afdb0e4e774f4f15ec4a34f0c3100c
### Operating system
- Windows
### Operating system version
- Windows 11
### Additional context
Originally reported by @JLBCS at https://forum.arduino.cc/t/iram-attr-questions/1297715
In the real world sketch shared there, [`IRAM_ATTR`](https://docs.espressif.com/projects/esp-idf/en/v4.3/esp32c3/api-guides/memory-types.html#how-to-place-code-in-iram) was used. This is a macro for an `__attribute__` declaration, provided by Espressif's esp-idf framework.
#### Related
- https://github.com/arduino/arduino-cli/issues/1191
- https://github.com/arduino/arduino-cli/issues/1253
- https://github.com/arduino/arduino-cli/issues/1269
- https://github.com/arduino/arduino-cli/issues/1591
- https://github.com/arduino/arduino-cli/issues/1618
- https://github.com/arduino/arduino-cli/issues/1785
- https://github.com/arduino/arduino-cli/issues/1822
- https://github.com/arduino/arduino-cli/issues/2161
- https://github.com/arduino/arduino-cli/issues/2525
- https://forum.arduino.cc/t/is-the-location-of-a-global-function-important/996378/18
- https://forum.arduino.cc/t/ide-mistakes-javascript-function-for-type/953022
- https://forum.arduino.cc/t/c-super-quotes-compiler-bug/990071
- https://forum.arduino.cc/t/over-length-line-in-editor-forces-forward-declaration/955571
- https://forum.arduino.cc/t/solved-multiple-ide-tabs-issue/988086
- https://forum.arduino.cc/t/declaration-of-functions/687199/11
- https://forum.arduino.cc/t/tab-local-structs/689088
- https://forum.arduino.cc/t/include-in-multiple-sketches/1133645/11
- https://forum.arduino.cc/t/compiler-flaw-probably-deliberate-infuriating/1146637
- https://forum.arduino.cc/t/does-the-ardiuno-compiler-fully-support-templates/1274584
<a name="workaround"></a>
#### Workaround
Manually add a function prototype to the sketch:
```cpp
void __attribute__(()) foo();
void loop() {}
void setup() {
foo();
}
void foo() {}
```
### Issue checklist
- [X] I searched for previous reports in [the issue tracker](https://github.com/arduino/arduino-cli/issues?q=)
- [X] I verified the problem still occurs when using the [nightly build](https://arduino.github.io/arduino-cli/dev/installation/#nightly-builds)
- [X] My report contains all necessary details
1 Like