Re: OT: Requesting C advice

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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

[Index of Archives]     [Current Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Yosemite News]     [Yosemite Photos]     [KDE Users]     [Fedora Tools]     [Fedora Docs]

  Powered by Linux