home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #19 / NN_1992_19.iso / spool / comp / os / os2 / programm / 4529 < prev    next >
Encoding:
Internet Message Format  |  1992-08-29  |  1.8 KB

  1. Path: sparky!uunet!gatech!rutgers!njitgw.njit.edu!hertz.njit.edu!dic5340
  2. From: dic5340@hertz.njit.edu (David Charlap)
  3. Newsgroups: comp.os.os2.programmer
  4. Subject: Re: C Set/2 Question in malloc
  5. Message-ID: <1992Aug28.210957.27794@njitgw.njit.edu>
  6. Date: 28 Aug 92 21:09:57 GMT
  7. References: <9208281644.AA10538@ucbvax.Berkeley.EDU>
  8. Sender: news@njit.edu
  9. Organization: New Jersey Institute of Technology, Newark, N.J.
  10. Lines: 37
  11. Nntp-Posting-Host: hertz.njit.edu
  12.  
  13. In article <9208281644.AA10538@ucbvax.Berkeley.EDU> LANSCHE@TOROLAB6.VNET.IBM.COM ("Martin Lansche") writes:
  14. >   I saw your append in the comp.os.os2.programmer forum.  I believe that
  15. >I can help.  C Set/2 is an ANSI compliant "C" compiler.  Sun's compiler
  16. >is K&R "C". The ANSI definition for malloc is:
  17. >
  18. >void * malloc(size_t);
  19. >
  20. >While the K&R definition is:
  21. >
  22. >char * malloc();
  23. >
  24. >K&R compilers will not complain about implicit casts between potentially
  25. >different sized pointers.  ANSI compilers do.  To explain the messages
  26. >
  27. >- (12,15) gives the line number (12) and the column number (15)
  28. >containing the operation that is illegal.
  29. >- (12,10) says the the operand is at column 10
  30. >- and (12,17) says the 2nd operand is at column 17
  31. >All of this is supposed to help you determine exactly where the error is
  32. >and to what the messages are referring.
  33. >
  34. >To fix the problem, add a cast to the malloc, i.e.
  35. >
  36. >array= (long *) malloc(50*sizeof(long);
  37.  
  38. But (void *) variables are supposed to be assignment compatible with
  39. all pointers.  Something's wrong here if that's required.
  40.  
  41. I just compiled that sample code under Unix with gcc 2.1 (using the
  42. -ansi and -pedantic options) and it compiled fine.
  43.  
  44.  
  45. -- 
  46.    |)  David Charlap           "I don't even represent myself
  47.   /|_  dic5340@hertz.njit.edu   sometimes so NJIT is right out!.
  48.  ((|,)
  49.   ~|~  Hi! I am a .signature virus, copy me into your .signature file.
  50.