[prog] [C] strings bug

Meredydd Luff meredydd at everybuddy.com
Thu Apr 10 15:30:35 EST 2003


Robert J. Hansen said:
>> When this function is called, the values of string1, string2, and
>> string3 are  undefined - they could technically be anything. Looking
>> at your output,
>
> According to C++98, globals are initialized to a value of 0 (NULL for
> pointers, 0.0 for doubles/floats) before main() is entered.  I believe
> C89 is the same way, but I wasn't able to find a definitive reference
> in a thirty-second check of K&R.
Well, I have less exalted sources to refer to, but I remember being taught
that with C++, unlike C, uninitialised variables were initialised to zero
by default, but that it was still bad style to rely on that feature.
Indeed, I prefer Java's attitude - "this variable may be used unassigned"
is a build-stopping error. If you're going to use a variable initialised
to zero, fine, but do it explicitly.
Meredydd
--
Maintainer, Everybuddy project
http://www.everybuddy.com/

AIM: blip109
MSN: blip109 at hotmail.com
Yahoo: modula7





More information about the Programming mailing list