Subject: Re: making programs 64bit clean
To: None <port-alpha@NetBSD.ORG, email@example.com>
From: Ross Harvey <firstname.lastname@example.org>
Date: 06/18/1998 13:18:48
> From port-alpha-owner-ross=teraflop.com@NetBSD.ORG Thu Jun 18 12:43:15 1998
> Date: Thu, 18 Jun 1998 06:28:08 -0700 (MST)
> Organization: Garbled User
> From: Tim Rightnour <email@example.com>
> To: port-alpha@NetBSD.ORG
> Subject: making programs 64bit clean
> I'm trying to make a pkg 64bit clean, and am running into an error that has me
> stumped. I resorted to typecasting just about everything, and Managed to cut
> the offending code down to one line:
> int i;
> (char **)malloc(i * sizeof(char **));
> which returns:
> warning: cast to pointer from integer of different size
> I've tried making i long, making the args to malloc (size_t), I'm at a
> complete loss here, any help would be appreciated. Thanks.
> Tim Rightnour - firstname.lastname@example.org
Hi Tim! Thanks for banging away at the packages on the alpha.
Here are some general guidelines w.r.t. malloc and 64-bitisms.
1. The file must include <stdlib.h>
2. It has not been necessary to cast the malloc return value for
many, many, years. It returns a void * so if the stdlib.h prototype
is in scope it can be assigned to any pointer type. In fact, it
is dangerous to cast the return value because that can mask other
errors...like this one... :-)
3. Don't worry about "i", it will be promoted anyway if <stdlib.h> is
in scope, and in this case it gets promoted when multipled by the
size_t result of sizeof.
4. A good place to start is to include the various *std* headers
just on general principles.
In this case you probably just don't have the malloc() prototype in scope,
(no stdlib.h) so of course malloc() defaults (badly) to int. You can use
all those cc(1) warning options to catch stuff like this.
If a program wants to lie about pointer types, it should declare and use void
* to hold them. If it absolutely must use integral types for sleazy pointer
games, then you should use ptrdiff_t, although any of size_t, ssize_t, or
even just "long" will actually work and be reasonably portable.