Newsgroups: comp.os.minix
Path: utzoo!henry
From: henry@utzoo.uucp (Henry Spencer)
Subject: Re: Minix/ST <stdio.h> problems.
Message-ID: <1988Oct28.182506.26095@utzoo.uucp>
Organization: U of Toronto Zoology
References: <249@cstw01.UUCP> <2598@sultra.UUCP>
Date: Fri, 28 Oct 88 18:25:06 GMT

In article <2598@sultra.UUCP> dtynan@sultra.UUCP (Der Tynan) writes:
>... I've always been partial to the idea that sizeof(char *) == sizeof(int).
>In fact, I've seen a lot of code (not necessarily my own), which assumes this.

Such code is broken.  Unfortunately, there *is* a lot of it about.

>If one needs sizeof(int) == 16, then use short.  It's my belief that if you
>have a true 32-bit address space (lucky you), then there's no reason to keep
>ints to a small size...

Can you say "performance"?  Ints are supposed to be the "natural" width
for the machine, which is often taken to mean the width that performs
best.  On the 16-bit 680x0s, there is a sticky decision to be made:
16-bit ints are considerably faster, 32-bit ints are more useful and
cause less trouble with poorly-written software.  Not an easy choice,
and there is no unanimity among C compilers on it.

>Of course, one should always use casts with NULL anyway.

No, the only place where NULL must be cast is as a function parameter.
But casting it *there* is very important.

>	if ((memptr = malloc(BUFSIZE)) == (char *)NULL)

This is silly; any compiler that isn't totally brain-dead will do exactly
the same thing with or without the cast.  Problems arise only when the
compiler cannot tell what the type is supposed to be, and function calls
are the only place where that really crops up.

(Note, a machine with 16-bit ints and 32-bit pointers has a related
problem with return values:  the calling function *must* know the correct
type of the return value.  Many programs are sloppy about this, since
the default type -- int -- happens to work right for pointer-valued
functions on VAXen and the like.  Not so when sizeof(int) != sizeof(char*).)
-- 
The dream *IS* alive...         |    Henry Spencer at U of Toronto Zoology
but not at NASA.                |uunet!attcan!utzoo!henry henry@zoo.toronto.edu
