Can gcc somehow initialize uninitialized pointers to NULL?
At work, we build our software on both gcc 4.1.2 as well as Sun Studio 12. The gcc version, running on Red Hat Enterprise Linux, has been running fine, 5 days a week, for several months.
We just rolled out our Solaris version though, and it crashes on startup, every day.
The stack trace brings us to code like this:
if( _timer == NULL ) {
_timer = new Timer(bunch, of, parameters);
}
_timer->StartTimer(_timeout);
And we have identified _timer as not having been initialized anywhere. So we believe _timer must be set to garbage data, which fails comparison to NULL, then gets StartTimer'ed without a timer ever being constructed.
The work is actually assigned to my colleague and he's verifying this. But meanwhile, I was curious: Why didn't our Linux (gcc) build crash, ever? I can assure you it's the same code—we use Perforce and strict labeling. I read that compilers do not initialize uninitialized pointers, so I'm confused.
Confirmation that gcc 4.1.2 absolutely cannot auto-initialize an uninitialized pointer, would answer this question. Or, ways it might.