Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!henry From: henry@utzoo.UUCP (Henry Spencer) Newsgroups: comp.lang.c Subject: Re: initializing null pointers Message-ID: <7654@utzoo.UUCP> Date: Tue, 10-Feb-87 15:42:52 EST Article-I.D.: utzoo.7654 Posted: Tue Feb 10 15:42:52 1987 Date-Received: Tue, 10-Feb-87 15:42:52 EST References: <347@bms-at.UUCP> <7614@utzoo.UUCP>, <8134@tekecs.TEK.COM> Organization: U of Toronto Zoology Lines: 25 > >> What about pointer arrays allocated with calloc()? Does one have to > >> initialize all the elements in a loop to be portable... > > > >Fraid so. What you might do, though, if you are willing to risk some small > >degree of unportability for the sake of efficiency, is first test an element > >of the array for equality to NULL... > > > >The small portability risk in this is the possibility that an all-zeros > >pointer might have magic properties (e.g. trap on any use of it). > > Or that you might, by chance, have tested a pointer that had been NULL in a > previous life! What previous life? They've just been initialized to all-zero-bits by calloc, remember? The only question is whether that's the same as NULL. (calloc != malloc) > The most portable thing to do is NEVER dereference a pointer that has not > been initialized... Who said anything about dereferencing? Please read my words again; all I suggested was comparing it to NULL. -- Legalize Henry Spencer @ U of Toronto Zoology freedom! {allegra,ihnp4,decvax,pyramid}!utzoo!henry