> From: Ian Lance Taylor <ian@airs.com> >> Paul Schlie <[EMAIL PROTECTED]> writes: >> Given that it would appear that the only time the compiler may attempt >> to optimize the allocation/use of an un-initialized variable, is when it >> knows for certain it hasn't been initialized; might it be preferable to >> then assign it a deterministic cheap value such as 0 which it may then >> presume during optimization, given all remaining alternatives would seem >> to have less desirable potential consequences? > > That would not be desirable in general when optimizing. The compiler > would not be able to consistently optimize away the initializations to > zero, so a correct program would wind up with useless instructions > which should make it larger and slower. Usually only a tiny bit > larger and slower, of course, but when optimizing most people prefer > the resulting code to run as fast as possible. Running as fast as > possible means omitting instructions which are not required. > > It would be perfectly reasonable to have a command line option to > initialize automatic variables to zero, of course.
- although I admit it's a bit of a stretch, there are circumstances (such as when using certain types of memories for physical storage such as possibly FLASH/EEPROM's which have substantially greater write times/overheads than read times/overheads, although may not be a great design choice for a variety of reasons) that it may be desirable to actually read a value to determine it's potential equivalence to a given value in an effort to eliminate an otherwise costly potentially unnecessary write. In which circumstances its logically resulting value is fully deterministic, although it's initial value may not be, nor am I aware of any machine which would ever trap a reference to any valid storage location regardless of its stored value, initialized or not?