FAQ - malloc array - clarify

Craig Jackson drilex1 dricejb at drilex.UUCP
Fri Sep 14 23:43:00 AEST 1990


A poster recently wondered why a statement like

double *ptr = (double *) malloc(ncols * sizeof(double));

gave lint complaints about the argument to malloc().

People here have been blathering on about broken compilers, erroneous lint
libraries, etc, thinking that 'sizeof()' is returning an int on that machine.

Wouldn't a more reasonable explanation be that 'ncols' is an int, and that
particular compiler treats 'int * unsigned' as 'int' (or 'long int')?  
I don't have all of the rules about value-preserving vs 
unsignedness-preserving burned into my head, but such an explanation 
sure makes sense to me...
-- 
Craig Jackson
dricejb at drilex.dri.mgh.com
{bbn,axiom,redsox,atexnet,ka3ovk}!drilex!{dricej,dricejb}



More information about the Comp.lang.c mailing list