Reputation: 1136
In the project I'm working on Xcode automatically initializes variables to 0 on startup/ at compile time, when I start the debug build. At least everything looks like it.
I'm often running into the problem, that I haven't initialized a variable to NULL - which works fine on my Mac - and when someone else compiles and starts the project (especially on Windows machines, as it's a multiplatform project), they get a EXC_BAD_ACCESS
, because == NULL
is false.
I'm pretty sure there exists a setting to turn this behavior off, or is it just coincidental, that the allocated memory is always fresh on my machine?
Upvotes: 1
Views: 1021
Reputation: 16046
It is likely just coincidental.
On about every modern multi user OS, when the OS gives new memory to the process, it erases all old contents, to not have information leak from one process to the other. So when you access some memory the first time, it apepars as if it is set to 0.
This will happen in certain situations more likely when using debug builds, since optimization often includes lowering the stack footprint, thus is reusing certain memory much earlier.
Upvotes: 3