To initialize or not initialize variables

Brian M McNamara v056ped5 at ubvmsd.cc.buffalo.edu
Thu Mar 28 16:38:05 AEST 1991


I was writing a program today that maintained an array of structures.
Near the end of writing the program, I realized that i needed one more
int variable in the structure. Everytime I compiled the program, it
worked correctly once. The second time  I ran the program, garbage
showed up in those fields rather than the initial zeros i wanted. 
After I realized what the problem was, debugging was obviously simple.

Why do programs work once when you have a bug like this? I have
see this same problem in many different languages using many different
compilers. This one was through Turbo C's editor environment.

Also, why don't they write compilers so that numeric data is initialized
to zero and character data is initialized to a single EOL?

Brian



More information about the Comp.lang.c mailing list