Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!usc!snorkelwacker.mit.edu!bloom-picayune.mit.edu!news From: scs@adam.mit.edu (Steve Summit) Newsgroups: comp.lang.c Subject: Re: To initialize or not initialize variables Message-ID: <1991Mar28.083659.29184@athena.mit.edu> Date: 28 Mar 91 08:36:59 GMT References: <67693@eerie.acsu.Buffalo.EDU> Sender: news@athena.mit.edu (News system) Reply-To: scs@adam.mit.edu Organization: Thermal Technologies, Cambridge, MA Lines: 23 In article <67693@eerie.acsu.Buffalo.EDU> v056ped5@ubvmsd.cc.buffalo.edu writes: >Also, why don't they write compilers so that numeric data is initialized >to zero and character data is initialized to a single EOL? Perhaps the simplest answer, though not terribly satisfying, is because "it's not done that way." Actually, statically-allocated data is guaranteed to be initialized to 0. (This translates to NULL pointers for character pointers, and '\0' for character arrays.) If you want consistent, predictable (though not necessarily useful) behavior for dynamically-allocated memory, use calloc() (but see the FAQ list for caveats, and more information about initialization and allocation in general). Given the realities of dynamic memory allocation, a better question might be, "why don't they write compilers so that numeric data is initialized to 2574 and character data is initialized to '\007'?" Steve Summit scs@adam.mit.edu