
Roland Schwarz <roland.schwarz@chello.at> writes:
Martin Bonner wrote:
You may be able to do a little better. The standard says "The storage for objects with static storage duration (3.7.1) shall be zeroinitialized (8.5) before any other initialization takes place." What is more, most normal operating systems give programs pages of memory that are zero-initialized, so compilers would have to do work to avoid this.
I think that means you can declare constructors and STILL have the object well behaved.
Do you mean: the object might be already zero initialized before the ctor runs? If yes: this is very dangerous to rely on!
No. This is required. The memory for an object with static-storage-duration MUST be zero initialized prior to the constructor running.
1) "Might": the standard does not require it.
Wrong.
2) E.g.: MSVC initializes memory to "CDCDCDCDCDCD...." in debugging builds, so there is at least one prominent case where the assumption is false.
It does this for automatic and heap-allocated objects (which is allowed). If it did it for static objects, it would be non-conforming. Anthony -- Anthony Williams Software Developer Just Software Solutions Ltd http://www.justsoftwaresolutions.co.uk