Path: utzoo!attcan!utgpu!jarvis.csri.toronto.edu!clyde.concordia.ca!uunet!mcsun!unido!mikros!mwtech!martin From: martin@mwtech.UUCP (Martin Weitzel) Newsgroups: comp.lang.c Subject: Representation of NULL and 0.0 (was Re: Zero Length Arrays ...) Message-ID: <545@mwtech.UUCP> Date: 15 Dec 89 15:05:52 GMT References: <2298@jato.Jpl.Nasa.Gov> <11715@smoke.BRL.MIL> <480@codonics.COM> <1989Dec2.210042.12668@twwells.com> <8129@cg-atla.UUCP> <1989 Reply-To: martin@mwtech.UUCP (Martin Weitzel) Organization: MIKROS Systemware, Darmstadt/W-Germany Lines: 40 In article <1989Dec14.182113.5398@twwells.com> bill@twwells.com (T. William Wells) writes: [most stuff deleted, because not significant for my question] > >Warning: null pointers and floating point zeros are *not* >necessarily represented by bit patterns of all zero bits. Sorry, my copy of the draft is not the most recent (we Europeans seem to have no easy way, to get an up-to-date *A*NSI-Standard :-/), but I allready guessed that a portable programm would require: foo(size_t n) { double *a; /* no a[n] in C */ a = malloc(n * sizeof *a); if (!a) abort();/* at least */ { size_t i = n; while (i--) a[i] = 0; } /* now we have an array of n zero-initialized double-s */ /* and can do whatever we must do with it .... */ : : free(a); } If the type of "a" would have been int or long, one could ommit the initialization loop and replace malloc with calloc, which may have a faster way to zero the allocated space. (Am I right so far?) Wouldn't it have been wise to add another 'calloc' for floating types and NULL pointers, as the initializing feature of calloc is weak in this respect? (As an aside, the pure existance of such a function would have warned all programmers, who are still in believe, they allways receive NULL-pointers or 0.0 from calloc). Now, how is the situation with statically allocated data (esp. not fully initialized arrays). The compiler 'knows' the exact data type in this situation (other than calloc in the above example) and could use 'the right' representation. What are the guarantees of the standard: zero bits or NULL resp. 0.0? -- <<< MW -- email: see header -- voice: 49-(0)6151-6 56 83 >>>