FAQ - malloc array - clarify

Conor P. Cahill cpcahil at virtech.uucp
Tue Sep 11 10:25:44 AEST 1990


In article <1803 at tuvie> hp at vmars.tuwien.ac.at (Peter Holzer) writes:
>cpcahil at virtech.uucp (Conor P. Cahill) writes:
>
>>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).

The argument to malloc is defined in the library (i.e. where malloc()
is encoded).  running lint against the source builds the lint library and
therefore the lint library will correctly reflect what the code has (besides,
without code, you can rebuild a lint library).

The problem that the original poster ran into is that on his system
the type of sizeof() is an integer.  However, the type of malloc's 
argument is an unsigned integer.

-- 
Conor P. Cahill            (703)430-9247        Virtual Technologies, Inc.,
uunet!virtech!cpcahil                           46030 Manekin Plaza, Suite 160
                                                Sterling, VA 22170 



More information about the Comp.lang.c mailing list