Newsgroups: comp.lang.c Path: utzoo!henry From: henry@utzoo.uucp (Henry Spencer) Subject: Re: Value of a null pointer Message-ID: <1988Apr24.090957.8517@utzoo.uucp> Organization: U of Toronto Zoology References: <4728@cup.portal.com> Date: Sun, 24 Apr 88 09:09:57 GMT > 1. An uninitialized external is set to zero bits... Wrong. This was never made entirely clear in K&R, but ANSI C makes it quite specific that an uninitialized external is set as if it were explicitly initialized to 0. > 2. One can use calloc to allocate an array of pointers. The initial value of > this array must be null pointers. calloc sets the area to zero bits. Wrong. Calloc sets its area to zero bits. That is not guaranteed to be zeros of any data type. Well, if you read the fine print it's probably guaranteed to be integer zeros, given that integers are pretty tightly defined to be binary, but it is *not* guaranteed to be pointer or floating-point zeros. > Also, does the new standard require that a cast of a literal zero always > does the right thing? That is, are > ptr_type_var = (ptr_type)0; /* assigns null pointer */ > ptr_type_var = 0; /* assigns null pointer */ > func( (ptr_type)0 ); /* function expecting pointer type */ Yes. This was true in K&R and it is true in ANSI C. Mind you, given the quantity of sloppy C code around, machine designers interested in C and/or Unix will think twice about making NULL anything but all-zero-bits, but they are within their rights to do so. -- "Noalias must go. This is | Henry Spencer @ U of Toronto Zoology non-negotiable." --DMR | {ihnp4,decvax,uunet!mnetor}!utzoo!henry