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

  1. Xref: sparky comp.os.os2.programmer:4525 comp.os.os2.apps:5629 comp.os.os2.misc:28525
  2. Path: sparky!uunet!cis.ohio-state.edu!pacific.mps.ohio-state.edu!linac!att!rutgers!njitgw.njit.edu!hertz.njit.edu!dic5340
  3. From: dic5340@hertz.njit.edu (David Charlap)
  4. Newsgroups: comp.os.os2.programmer,comp.os.os2.apps,comp.os.os2.misc
  5. Subject: Re: C Set/2 Question in malloc
  6. Message-ID: <1992Aug28.205857.23557@njitgw.njit.edu>
  7. Date: 28 Aug 92 20:58:57 GMT
  8. References: <1992Aug28.154836.12867@natinst.com>
  9. Sender: news@njit.edu
  10. Organization: New Jersey Institute of Technology, Newark, N.J.
  11. Lines: 67
  12. Nntp-Posting-Host: hertz.njit.edu
  13.  
  14. In article <1992Aug28.154836.12867@natinst.com> uma@natinst.com (Uma Arunkumar) writes:
  15. >
  16. >****************** C Set/2   QUESTION ************************
  17. >I am trying to compile a small program (to solve a problem in a huge program)
  18. >in C Set/2 version 1.00.
  19. >This program was taken from the C Set/2 Program Example given for malloc
  20. >using KWIKINF.
  21. >***************************************************************
  22. >
  23. >The program is given below:
  24. >       
  25. >#include <stdio.h>
  26. >#include<malloc.h>
  27.  
  28. Why are you using <malloc.h>?  Use <stdlib.h> for malloc().  It's ANSI
  29. compliant.  This shouldn't be causing you a problem, though.
  30.  
  31. >main()
  32. >{
  33. >   char str[50];
  34. >   long  *array;
  35. >   int i;
  36. >   for (i=0; i<50; i++)
  37. >       str[i]='m';
  38. >
  39. >  if  (( array= malloc(50 * sizeof(long)))!= NULL)
  40. >     for (i=0; i<50; i++)
  41. >       *array++=1;
  42. >
  43. >}
  44. >   
  45. >*********************************************************
  46. >
  47. >When I compile giving the command 
  48. >            icc /c /w3 /o+ sample.c 
  49. >
  50. >       I get the following error messages:
  51. >
  52. >
  53. >SAMPLE.C(12:15) : error EDC0117: The operation between these types is not valid.
  54. >SAMPLE.C(12:10) : informational EDC0140: Operand has type pointer to  signed long integer .
  55. >SAMPLE.C(12:17) : informational EDC0140: Operand has type signed integer .
  56. >
  57. >This program compiles without any error in C compiler in Sun.
  58. >
  59. >What is wrong in the above code?
  60.  
  61. The problem is the *array++=1; statement.  array is an array of longs.
  62. 1 is an int. (short).  Try one of these:
  63.  
  64.     *array++ = 1L;
  65.  
  66. or:
  67.  
  68.     (SHORT)(*array++) = 1;
  69.  
  70. The first example is probably better.  
  71.  
  72. If you don't want to change anythings, try using a lower warning level
  73. (/w3 may be too high for this kind of operation).  Or turn off
  74. ANSI-compliant type-checking.
  75.  
  76. -- 
  77.    |)  David Charlap           "I don't even represent myself
  78.   /|_  dic5340@hertz.njit.edu   sometimes so NJIT is right out!.
  79.  ((|,)
  80.   ~|~  Hi! I am a .signature virus, copy me into your .signature file.
  81.