Article View: comp.os.os2.programmer
Article #1241Re: C Set/2 Question in malloc
From: David Charlap
Date: Fri, 28 Aug 1992 21:09
Date: Fri, 28 Aug 1992 21:09
37 lines
1919 bytes
1919 bytes
In article <9208281644.AA10538@ucbvax.Berkeley.EDU> LANSCHE@TOROLAB6.VNET.IBM.COM ("Martin Lansche") writes:
> I saw your append in the comp.os.os2.programmer forum. I believe that
>I can help. C Set/2 is an ANSI compliant "C" compiler. Sun's compiler
>is K&R "C". The ANSI definition for malloc is:
>
>void * malloc(size_t);
>
>While the K&R definition is:
>
>char * malloc();
>
>K&R compilers will not complain about implicit casts between potentially
>different sized pointers. ANSI compilers do. To explain the messages
>
>- (12,15) gives the line number (12) and the column number (15)
>containing the operation that is illegal.
>- (12,10) says the the operand is at column 10
>- and (12,17) says the 2nd operand is at column 17
>All of this is supposed to help you determine exactly where the error is
>and to what the messages are referring.
>
>To fix the problem, add a cast to the malloc, i.e.
>
>array= (long *) malloc(50*sizeof(long);
But (void *) variables are supposed to be assignment compatible with
all pointers. Something's wrong here if that's required.
I just compiled that sample code under Unix with gcc 2.1 (using the
-ansi and -pedantic options) and it compiled fine.
--
|) David Charlap "I don't even represent myself
/|_ dic5340@hertz.njit.edu sometimes so NJIT is right out!.
((|,)
~|~ Hi! I am a .signature virus, copy me into your .signature file.
Technical Details
Message-ID:
<1992Aug28.210957.27794@njitgw.njit.edu>Path:
arc1-ca.pugleaf.net!sparky!uunet!gatech!rutgers!njitgw.njit.edu!hertz.njit.edu!dic5340References:
<9208281644.AA10538@ucbvax.Berkeley.EDU>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!sparky!uunet!gatech!rutgers!njitgw.njit.edu!hertz.njit.edu!dic5340 From: dic5340@hertz.njit.edu (David Charlap) Newsgroups: comp.os.os2.programmer Subject: Re: C Set/2 Question in malloc Message-ID: <1992Aug28.210957.27794@njitgw.njit.edu> Date: 28 Aug 92 21:09:57 GMT References: <9208281644.AA10538@ucbvax.Berkeley.EDU> Sender: news@njit.edu Organization: New Jersey Institute of Technology, Newark, N.J. Lines: 37 Nntp-Posting-Host: hertz.njit.edu