Re: OT: Requesting C advice

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

 



On Thu, 31 May 2007, Mike McCarty wrote:

Les wrote:
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

IIRC, it was mentioned in K&R v1.

My K&R1 is lost to history 8^(, but my H&S 3rd edition spent a lot of space on the difference between "traditional" or "K&R" and ANSI compilers. In the section on default initialization the only static vars that were *not* required to be initialized in traditional compilers were unions. The note says that some traditional compilers would not permit such initializations. The ANSI requirement is that the union be initialized to the default for the first element.

The other note was that some traditional compilers would initialize a static float/double to all-bits-zero, even if that was not the representation of 0.0. That's not permitted in ANSI C.


[snip]

    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.

Older? ANSI C is since 1989. I guess one could characterize 19 years
as "older". :-)

And those older-than-dirt compilers were even broken for their age if that's the way they behaved.


Mike


--
		Matthew Saltzman

Clemson University Math Sciences
mjs AT clemson DOT edu
http://www.math.clemson.edu/~mjs


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

  Powered by Linux