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

  1. Path: sparky!uunet!gatech!darwin.sura.net!dtix!mimsy!pr
  2. From: pr@umiacs.umd.edu (Jesus Rodriguez)
  3. Newsgroups: comp.os.os2.programmer
  4. Subject: Re: C Set/2 Question in malloc
  5. Message-ID: <59958@mimsy.umd.edu>
  6. Date: 28 Aug 92 18:18:44 GMT
  7. References: <1992Aug28.154836.12867@natinst.com> <19920828.105606.807@almaden.ibm.com>
  8. Sender: news@mimsy.umd.edu
  9. Organization: University of Maryland Institute for Advanced Computer Studies
  10. Lines: 73
  11. Originator: pr@fnord.umiacs.umd.edu
  12.  
  13.  
  14. In article <19920828.105606.807@almaden.ibm.com>, ameline@vnet.ibm.com (Ian Ameline) writes:
  15. |> In article <1992Aug28.154836.12867@natinst.com>,
  16. |> uma@natinst.com (Uma Arunkumar) writes:
  17. |> >
  18. |> >****************** C Set/2   QUESTION ************************
  19. |> >I am trying to compile a small program (to solve a problem in a huge program)
  20. |> >in C Set/2 version 1.00.
  21. |> >This program was taken from the C Set/2 Program Example given for malloc
  22. |> >using KWIKINF.
  23. |> >
  24. |> >***************************************************************
  25. |> >The program is given below:
  26. |> >
  27. |> >#include <stdio.h>
  28. |> >#include<malloc.h>
  29. |> >main()
  30. |> >{
  31. |> >   char str[50];
  32. |> >   long  *array;
  33. |> >   int i;
  34. |> >   for (i=0; i<50; i++)
  35. |> >       str[i]='m';
  36. |> >
  37. |> >  if  (( array= malloc(50 * sizeof(long)))!= NULL)
  38. |> >     for (i=0; i<50; i++)
  39. |> >       *array++=1;
  40. |> >
  41. |> >}
  42. |> >
  43. |> >*********************************************************
  44. |> >
  45. |> >When I compile giving the command
  46. |> >            icc /c /w3 /o+ sample.c
  47. |> >
  48. |> >       I get the following error messages:
  49. |> >
  50. |> >SAMPLE.C(12:15) : error EDC0117: The operation between these types is not valid.
  51. |> >SAMPLE.C(12:10) : informational EDC0140: Operand has type pointer to  signed long integer .
  52. |> >SAMPLE.C(12:17) : informational EDC0140: Operand has type signed integer .
  53. |> >
  54. |> >This program compiles without any error in C compiler in Sun.
  55. |> >
  56. |> >What is wrong in the above code?
  57. |> >
  58. |> >I WOULD HIGHLY APPRECIATE SOME HELP.
  59. |> >
  60. |> >Thanks in advance.
  61. |> >
  62.  
  63. |> >My Email address is uma@natinst.com.
  64. |> >
  65. |> >uma.
  66. |> >
  67. |> 
  68. |>    The problem is malloc.h. It's there for backwards compatibility with
  69. |> MS and other pre-ANSI compilers. When using these headers, use the /Sm
  70. |> option, so we won't enforce the ANSI standard as strictly, or use
  71. |> stdlib.h.
  72. |> 
  73. |> Regards,
  74. |> Ian.
  75.  
  76. The problem is not malloc.h or the need for stdlib.h  it is as someone posted before.
  77.  
  78. |> >  if  (( array= malloc(50 * sizeof(long)))!= NULL)
  79.  
  80. this line should read 
  81. if (( array = (long *) malloc(50 * sizeof(long))) != NULL)
  82.                ^^^^^^^ this is what needs to be added to the line.  
  83.  
  84. Jesus M. Rodriguez
  85. pr@umiacs.umd.edu
  86.