Does Arduino support tail call cancellation?

I was wondering if the standard Arduino environment supports tail call cancellation ... Does anyone know something about this?

+4
source share
2 answers

Tail rejection is indeed supported and enabled by default in the Arduino environment. This is quite standard in the microcontroller world, where debugging tools, such as the correct stack frames, are sacrificed for memory efficiency.

Here's the 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 on the console, which requires more recursive calls than the available bytes of RAM.

+1
source

Most C compilers do not support tail call removal. (this concept is not in the standard C).

Some recent C compilers may support it (only when optimized strongly), in very limited cases. In particular, GCC (latest version, for example 4.6 or 4.7).

You can try the simple C function and compile it and look at the generated assembly.

0
source

Source: https://habr.com/ru/post/1445124/


All Articles