initializing null pointers
jans at stalker.UUCP
jans at stalker.UUCP
Sat Feb 7 02:04:11 AEST 1987
In article <7614 at utzoo.UUCP> henry at utzoo.UUCP (Henry Spencer) writes:
>> 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!
The most portable thing to do is NEVER dereference a pointer that has not been
initialized. Some micro compilers I've used don't even initialize automatics!
:::::: Artificial Intelligence Machines --- Smalltalk Project ::::::
:::::: Jan Steinman Box 1000, MS 60-405 (w)503/685-2956 ::::::
:::::: tektronix!tekecs!jans Wilsonville, OR 97070 (h)503/657-7703 ::::::
More information about the Comp.lang.c
mailing list