Loop optimization
"Jérôme M. Berger"
jeberger at free.fr
Sat May 15 08:02:33 PDT 2010
div0 wrote:
> Jérôme M. Berger wrote:
>> That depends. In C/C++, the default value for any global variable
>> is to have all bits set to 0 whatever that means for the actual data
>> type.
>
> No it's not, it's always uninitialized.
>
According to the C89 standard and onwards it *must* be initialized
to 0. If it isn't then your implementation isn't standard compliant
(needless to say, gcc, Visual, llvm, icc and dmc are all standard
compliant, so you won't have any difficulty checking).
> Visual studio will initialise memory & a functions stack segment with
> 0xcd, but only in debug builds. In release mode you get what was already
> there. That used to be the case with gcc (which used 0xdeadbeef) as well
> unless they've changed it.
>
This does not concern global variables. Therefore the second part
of my message applies, the part you didn't quote:
> The default value for local variables and malloc/new memory is
> "whatever was in this place in memory before" which can be anything.
> The default value for calloc is to have all bits to 0 as for global
> variables.
I should have added that some compiler / standard libraries allow
you to have a default initialization value for debugging purpose.
Jerome
--
mailto:jeberger at free.fr
http://jeberger.free.fr
Jabber: jeberger at jabber.fr
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 198 bytes
Desc: OpenPGP digital signature
URL: <http://lists.puremagic.com/pipermail/digitalmars-d-learn/attachments/20100515/3c3d379d/attachment.pgp>
More information about the Digitalmars-d-learn
mailing list