Date: Mon, 16 Sep 1996 15:30:34 -0700 (PDT) From: Samuel Vincent To: Cesar Scarpini Rabak cc: kagel AT dg1 DOT bloomberg DOT com, thoni AT softlab DOT se, djgpp AT delorie DOT com Subject: Re: Possible static data zeroisation bug in DJGPP v2? In-Reply-To: <1.5.4.16.19960916173527.29e7e9f6@dmeasc.rc.ipt.br> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII On Mon, 16 Sep 1996, Cesar Scarpini Rabak wrote: > At 13:16 16/09/96 -0700, Samuel Vincent wrote: > >On Mon, 16 Sep 1996, Cesar Scarpini Rabak wrote: > > > >> Excerpt from K&R Book 2nd ed. pg 40: > >> "...External and static variables are initialized to zero by default." > >> > >> I have no ANSI/ISO standard handy by now, but it is on the standard as well > >> (I think on section four). > > > >You must forgive me for my disbelief, but how can an "external" variable > >be initialized at all? It's initialized elsewhere, where it is > >defined, not declared (externally declared or not...) > > Have you heard about a piece of code that runs BEFORE the very fisrt line of > your program runs (in DJGPP is in crt0.o...) the C Run Time start up code? > > One of its functions is precisely to do this chore. To do precisely what chore? If in a module named whatever.c I have: int somevar=10; Then in whatelse.c I have: extern somevar; Are you trying to tell me some piece of code in the runtime crt0.o module is going to scan for all variables and reset my 10 to a zero because it was extern in a module???? I don't think so. And as far as static variables go the same thing applies. Variable initializations of globals and statics are saved in the object code as the intialized variable (in other words, computed at compile-time.) They aren't initialized at runtime! > >As far as static variables go, I don't have that info available, but > >it would make sense to zero it yourself anyway. I believe ANSI says > >absolutely nothing is initialized unless you do it yourself. > > > > Sorry, but the Standard says the converse. Can you quote the ANSI spec that states this and where in the ANSI specs it is? -Sam