Path: utzoo!mnetor!uunet!lll-winken!lll-lcc!ames!umd5!trantor.umd.edu!chris From: chris@trantor.umd.edu (Chris Torek) Newsgroups: comp.lang.c Subject: Re: Caution for those considering MSC 5.0 Message-ID: <2328@umd5.umd.edu> Date: 20 Feb 88 14:24:16 GMT References: <11754@brl-adm.ARPA> <620@viper.Lynx.MN.Org> <278@ho7cad.ATT.COM> <2635@haddock.ISC.COM> <1221@wjvax.UUCP> Sender: ris@umd5.umd.edu Reply-To: chris@trantor.umd.edu (Chris Torek) Organization: University of Maryland, College Park Lines: 30 In article <1221@wjvax.UUCP> brett@wjvax.UUCP (Brett Galloway) writes: >It has long bothered me that C guarantees that uninitialized data of static >extent gets initialized to 0. Personally, I *never* rely on that fact, for >two reasons. One is a matter of style (see above). The other is a matter >of principle. This guarantee is useless and can introduce enormous >inefficiencies. Unless your machine obeys the convenient kludge that binary 0 >translates to a 0 object of every type, then in general a copy of the entire >uninitialized data space must be put in the executable and loaded into >memory. Something like BSS is completely useless then. I will not argue on the point of style, but the latter is wrong. C has very few basic types (there are more in the dpANS than in K&R, but still few enough); hence something like BSS can always be used, even if the machine architecture has something like tag bits. The key idea here is that a small amount of code can replace a large amount of data: 16 (if that happens to be the number) separate kinds of `bss' can be used to initialise the 16 kinds of zero. Arrays of structures containing differing kinds of zeros can be set with runtime startup loops: >In those cases where I have a lot of data that needs to be initialized, it >is usually the case that it is fairly simple to initialize with code, and so >I just keep a static initialized flag to indicate whether or not to >initialize the rest. The compiler can do this implicitly. C++ does this sort of thing for static constructors, for instance. -- In-Real-Life: Chris Torek, Univ of MD Computer Science, +1 301 454 7163 (hiding out on trantor.umd.edu until mimsy is reassembled in its new home) Domain: chris@mimsy.umd.edu Path: not easily reachable