OT: Requesting C advice

Les hlhowell at pacbell.net
Thu May 31 16:38:28 UTC 2007


On Thu, 2007-05-31 at 05:52 -0500, Mike McCarty wrote:

> Andy Green wrote:
> > Mike McCarty wrote:
> 
> [snip]
> 
> >>C doesn't initialize what? It initializes all used variables.
> > 
> > 
> > Not if they're on the stack.  You should get a compiler warning
> > nowadays... but don't count on it!
> 
> Erm, C knows nothing about a "stack". However, it is true
> that automatic variable are not necessarily initialized.
> I should have stated that all statically allocated variables
> are initialized. Thanks for the correction.
> 
> Mike
> -- 

That must be something recent.  Also some people believed that it did in
the past, but it did not.  The variables are just assigned space.  The
contents of the space was whatever was left from the prior use.  Since
many developers reboot before starting development, the space is often
preset to 0, due to memory checks or perhaps a behavior of some dynamic
ram operation, they believed the variables were initiaized, but they
were not.  This was as of 2000 on a SUN Solaris 8 system using K&R.  I
know this for a fact.  As to how different compilers deal with it, the
static variable space is between the initial entry jump and the
beginning of code in most designs, and that space may be initialized by
the compiler at compile time, such that uninitialized variables are
preset to 0.  But the original K&R spec did not include initializing
variables except explicitly.

    This part I am sure of, because I have had to fix many, many peoples
code due to this belief.  The ANSI comittee may have changed the
standard, but I would bet that a lot of older compilers still generate
code with no initialization.

Regards,
Les H
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://listman.redhat.com/archives/fedora-list/attachments/20070531/a5b29202/attachment-0001.htm>


More information about the fedora-list mailing list