FAQ - malloc array - clarify

Peter Holzer hp at vmars.tuwien.ac.at
Tue Sep 11 00:17:19 AEST 1990


cpcahil at virtech.uucp (Conor P. Cahill) writes:

>In article <8056 at helios.TAMU.EDU> jdm5548 at diamond.tamu.edu (James Darrell McCauley) writes:

>   array = (double **)malloc(nrows * sizeof(double *));

>>  for(i = 0; i < nrows; i++)
>>    array[i] = (double *)malloc(ncolumns * sizeof(double));

>>malloc, arg. 1 used inconsistently	llib-lc(383)  ::  test.c(8)
>>malloc, arg. 1 used inconsistently	llib-lc(383)  ::  test.c(10)

>This is caused by the argument to malloc being unsigned, not signed.  A
>cast in your code will fix this.

No! Don't fix your code, which is correct. Fix the lint library.
The argument to malloc should be the type returned by sizeof (): size_t
(an unsigned integral type).
--
|    _	| Peter J. Holzer			| Think of it	|
| |_|_)	| Technische Universitaet Wien		| as evolution	|
| | |	| hp at vmars.tuwien.ac.at			| in action!	|
| __/  	| ...!uunet!mcsun!tuvie!vmars!hp	|     Tony Rand	|



More information about the Comp.lang.c mailing list