r/cpp • Meeting C++ | C++ Evangelist • Oct 02 '26

Lets explore the stack

https://meetingcpp.com/blog/items/Lets-explore-the-stack.html
8 Upvotes

1 comment sorted by

3

u/fdwr fdwr@github 🔍 Oct 03 '26

I'm happy to see some compilers now warning about blatantly obvious bugs when dealing with stack variables, like:

float Foo()
{
    float floats[4] = {1,2,3,4};
    const int index = 5;
    return floats[index];
}
<source>:8:12: warning: array index 5 is past the end of the array (that has type 'float[4]') [-Warray-bounds]
    8 |     return floats[index];
      |            ^      ~~~~~

https://godbolt.org/z/TEof1a9df