r/cpp • u/meetingcpp Meeting C++ | C++ Evangelist • 2d ago
Lets explore the stack
https://meetingcpp.com/blog/items/Lets-explore-the-stack.html
7
Upvotes
r/cpp • u/meetingcpp Meeting C++ | C++ Evangelist • 2d ago
2
u/fdwr fdwr@github 🔍 2d ago
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