gcc and NULL function pointers.

Daniel Jimenez djimenez at ringer.cs.utsa.edu
Wed Jun 26 15:35:08 AEST 1991


In article <XZ4C6T6 at xds13.ferranti.com> peter at ficc.ferranti.com (Peter da Silva) writes:
>In article <16481 at smoke.brl.mil> gwyn at smoke.brl.mil (Doug Gwyn) writes:
>> In article <C62C9-2 at xds13.ferranti.com> peter at 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 <stdlib.h> 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 at ringer.cs.utsa.edu	*  This Sun terminal makes everything
*    dajim at lonestar.utsa.edu		*  I write seem important.
* Opinions expressed here are mine only, and not those of UTSA.



More information about the Comp.std.c mailing list