Upon compiling a sketch using the Arduino IDE, a message like the following gets displayed in the console:
Global variables use 1540 bytes (75%) of dynamic memory, leaving 508 bytes for local variables. Maximum is 2048 bytes.
In addition, it seems that if the global variables use exceeds around 75% of total dynamic memory, the following message gets displayed in addition:
Low memory available, stability problems may occur.
So, it seems that by using the IDE in a regular way, the compiler does not ensure that local variables memory allocation won't cause any RAM overflow during program execution. Instead, it just displays a warning message when little RAM is left for local variables.
This can lead to program malfunctions at execution time, if local variables happen to take up more space than the remaining RAM.
How can one have the compiler detect whether local variables memory allocation will cause RAM overflow during execution or not, and warn the user at compile time only in those specific cases?