3 ms·
"Before the switch to heap memory, this program probably ran just fine because the stack allocated memory will probably have a '\0' character at the end on acci
by tylerc230 15y ago
"Before the switch to heap memory, this program probably ran just fine because the stack allocated memory will probably have a '\0' character at the end on accident."
Stack memory is not preinitialized to '0' either so using stack memory would show this 'defect' as well (as others have pointed out this is a defect in the calling code, not in copy).
- apu 15y agoI think that depends on compiler, although it's been a while since I've done C, so I might be wrong.
- zedshaw 15y agoIt's fairly vague in the standard, but most of the time this is what happens so nobody hits the bug. Also, many OS are notorious for being loose with the stack and strict on the heap for various reasons.
- Roboprog 15y agoEven if the stack was 0 filled at startup, it won't be after you call something else, and that other code returns. The stack will simply be loaded with the final values of auto vars from the called routines, as well as return addresses and other such stack frame tracking.