Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!swrinde!ringer!djimenez From: djimenez@ringer.cs.utsa.edu (Daniel Jimenez) Newsgroups: comp.std.c Subject: Re: gcc and NULL function pointers. Message-ID: <1991Jun26.053508.3634@ringer.cs.utsa.edu> Date: 26 Jun 91 05:35:08 GMT References: <16481@smoke.brl.mil> Organization: University of Texas at San Antonio, San Antonio, Texas Lines: 52 In article peter@ficc.ferranti.com (Peter da Silva) writes: >In article <16481@smoke.brl.mil> gwyn@smoke.brl.mil (Doug Gwyn) writes: >> In article peter@ficc.ferranti.com (Peter da Silva) writes: >> >> What about systems where different pointer types have different sizes? >> >Then a different definition of NULL is appropriate. >depends entirely on the machine. >[more stuff deleted] >> If you declare it as, say, >> something that will work as an int*, then it cannot work as a char* on >> a system where different pointer types have different sizes. > >That's right, and on that system you use "0". If ints and pointers *also* >have different sizes, you're screwed. Too bad. I thought 0 in a context where a pointer is expected (e.g., int *p; p = 0;) wasn't the integer 0, rather whatever that machine's representation of a null pointer is. So it shouldn't matter if a pointer is 21.5 bits and an integer is 67 bits; '0' is a pointer value, which could be all bits zero or some other unique value. Anyway, if you have a machine where pointers to different types are of different sizes, then you have much bigger problems than what to #define NULL as. Like, let's say your machine has one size for character pointers and another for integer pointers. Let's also say that your file, like mine, contains char *malloc (blah blah blah); What if you wanted to allocate space for an integer like this: int *p; ... /* decision made to allocate integer */ p = (int *) malloc (sizeof (int)); (maybe you would want to do this in a situation where int*'s are 16 bits and ints are 32 bits, to save space) malloc would return a value of one size which would be a valid character pointer, but the wrong size for an integer pointer. I've never heard of machines like that. Could someone give an example? For what it's worth, here's my opinion on NULL: We should all contribute to a fund to help build a time machine so someone can go back in time and tell K&R to include something like Pascal's nil in C. :-) -- * Daniel A. Jimenez * Please excuse my longwindedness. * djimenez@ringer.cs.utsa.edu * This Sun terminal makes everything * dajim@lonestar.utsa.edu * I write seem important. * Opinions expressed here are mine only, and not those of UTSA.