3 ms·
In C that compiler is allowed to stack probe. The compilers just make you opt into it with -fstack-check and the like to make sure they didn't break some of yo
by monocasa 7y ago
In C that compiler is allowed to stack probe. The compilers just make you opt into it with -fstack-check and the like to make sure they didn't break some of your terribly written code.
- saagarjha 7y agoThat code is standards-compliant, because the standard has no knowledge of the stack. I actually had those flags enabled when I was messing around with it and they did nothing useful so I chose to leave them out. (Yes, the compiler will probe the stack–but only if you alloca, it seems. Nobody seems to have extended this protection to stack frames bloated by automatic variables.)
- monocasa 7y agoI couldn't get clang to, and gcc seems to be omitting the checks in some cases with your recursive call to foo (maybe it realizes that 'a' isn't actually accessed, but still emits the increase and decrease?). But gcc given a program that passes the address of 'a' into another function outside the compilation unit does emit stack probes with -fstack-check and -fstack-protector-all. https://godbolt.org/z/jHwZiG https://godbolt.org/z/jHwZiG And I don't care if they didn't come out and say it in the spec. If your program depends on overflowing the stack into other regions of memory you need to be taken out into the street and publicly dealt with as an example to others. That being said, I'm sure there's something about implementation defined behavior around exceeding the platform's max for automatic storage duration objects. If not I may try to sneak that into C2X, lol.