SIZEOF
Guy Harris
guy at rlgvax.UUCP
Wed Jan 30 11:22:20 AEST 1985
> The problem of passing 0 for a null pointer (as a parameter), and
> the solution of "#define NULL ...", as pointed out by P.Curran,
> is valid.
As you state below, there are machines where sizeof(char *) != sizeof(int *).
This solution (#define NULL ((char *)0)) is NOT valid on those machines.
> The only generally useable solution
> that I know of is -
> #define NULL 0 /** when sizeof(xxx *) == sizeof(int) **/
> #define NULL 0L /** when sizeof(xxx *) == sizeof(long) **/
This isn't a solution. There may be machines in which the bit pattern
that (char *)0 represents is something other than N zeros, where N is
the number of bits in an "int" or a "long int".
> One possible solution for the future could be the use of -
> #define NULL ((void *)0)
> which seems compatable with the notation of (void *) being a generic
> pointer type.
This won't work either. If a routine expects an "int *", dammit, it
expects an "int *", not an "int", not a "long int", not a "char *", and
not a "void *". What is so d*mn difficult about putting in pointer casts?
It's second nature to me now, and has been for several years - dating
back to PDP-11 days when it wasn't a problem.
Don't think of C as structured assembler, where you "know" what's
"really happening". Use it as a typed language, albeit with weak type
checking. Trust me, you'll be happier for doing so.
Can we put this discussion to bed now, with the conclusion that the only
correct solution to the problem, pending ANSI Standard C with the ability
to import the declaration of the arguments to a routine, is to put the
****** pointer casts in?
Guy Harris
{seismo,ihnp4,allegra}!rlgvax!guy
More information about the Comp.lang.c
mailing list