I was wondering if the standard Arduino environment support tail call elimination... Does anyone know something about it?
Tail call elimination is indeed supported and enabled by default in Arduino IDE. This is quite standard for micro-controller world where debug aids like proper stack frames are sacrificed for memory efficiency.
Here's a test:
const int RAM_SIZE_IN_BYTES = 2048;
void f(int i) {
Serial.println(i);
if(i == 0) return;
else f(i-1);
}
void setup() {
Serial.begin(9600);
f(RAM_SIZE_IN_BYTES);
}
void loop() {
}
This code prints numbers from 2048 to 0 to the console using a recursive function, which (without tail call optimization) requires more nested calls than available RAM bytes.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With