Article View: comp.os.os2.programmer
Article #1227Re: C Set/2 Question in malloc
From: Jesus Rodriguez
Date: Fri, 28 Aug 1992 18:18
Date: Fri, 28 Aug 1992 18:18
73 lines
2743 bytes
2743 bytes
In article <19920828.105606.807@almaden.ibm.com>, ameline@vnet.ibm.com (Ian Ameline) writes:
|> In article <1992Aug28.154836.12867@natinst.com>,
|> uma@natinst.com (Uma Arunkumar) writes:
|> >
|> >****************** C Set/2 QUESTION ************************
|> >I am trying to compile a small program (to solve a problem in a huge program)
|> >in C Set/2 version 1.00.
|> >This program was taken from the C Set/2 Program Example given for malloc
|> >using KWIKINF.
|> >
|> >***************************************************************
|> >The program is given below:
|> >
|> >#include <stdio.h>
|> >#include<malloc.h>
|> >main()
|> >{
|> > char str[50];
|> > long *array;
|> > int i;
|> > for (i=0; i<50; i++)
|> > str[i]='m';
|> >
|> > if (( array= malloc(50 * sizeof(long)))!= NULL)
|> > for (i=0; i<50; i++)
|> > *array++=1;
|> >
|> >}
|> >
|> >*********************************************************
|> >
|> >When I compile giving the command
|> > icc /c /w3 /o+ sample.c
|> >
|> > I get the following error messages:
|> >
|> >SAMPLE.C(12:15) : error EDC0117: The operation between these types is not valid.
|> >SAMPLE.C(12:10) : informational EDC0140: Operand has type pointer to signed long integer .
|> >SAMPLE.C(12:17) : informational EDC0140: Operand has type signed integer .
|> >
|> >This program compiles without any error in C compiler in Sun.
|> >
|> >What is wrong in the above code?
|> >
|> >I WOULD HIGHLY APPRECIATE SOME HELP.
|> >
|> >Thanks in advance.
|> >
|> >My Email address is uma@natinst.com.
|> >
|> >uma.
|> >
|>
|> The problem is malloc.h. It's there for backwards compatibility with
|> MS and other pre-ANSI compilers. When using these headers, use the /Sm
|> option, so we won't enforce the ANSI standard as strictly, or use
|> stdlib.h.
|>
|> Regards,
|> Ian.
The problem is not malloc.h or the need for stdlib.h it is as someone posted before.
|> > if (( array= malloc(50 * sizeof(long)))!= NULL)
this line should read
if (( array = (long *) malloc(50 * sizeof(long))) != NULL)
^^^^^^^ this is what needs to be added to the line.
Jesus M. Rodriguez
pr@umiacs.umd.edu
Technical Details
Message-ID:
<59958@mimsy.umd.edu>Path:
arc1-ca.pugleaf.net!sparky!uunet!gatech!darwin.sura.net!dtix!mimsy!prReferences:
<1992Aug28.154836.12867@natinst.com> <19920828.105606.807@almaden.ibm.com>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!sparky!uunet!gatech!darwin.sura.net!dtix!mimsy!pr From: pr@umiacs.umd.edu (Jesus Rodriguez) Newsgroups: comp.os.os2.programmer Subject: Re: C Set/2 Question in malloc Message-ID: <59958@mimsy.umd.edu> Date: 28 Aug 92 18:18:44 GMT References: <1992Aug28.154836.12867@natinst.com> <19920828.105606.807@almaden.ibm.com> Sender: news@mimsy.umd.edu Organization: University of Maryland Institute for Advanced Computer Studies Lines: 73 Originator: pr@fnord.umiacs.umd.edu