Article View: comp.os.os2.programmer
Article #1238Re: C Set/2 Question in malloc
From: David Charlap
Date: Fri, 28 Aug 1992 20:58
Date: Fri, 28 Aug 1992 20:58
67 lines
2571 bytes
2571 bytes
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>
Why are you using <malloc.h>? Use <stdlib.h> for malloc(). It's ANSI
compliant. This shouldn't be causing you a problem, though.
>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?
The problem is the *array++=1; statement. array is an array of longs.
1 is an int. (short). Try one of these:
*array++ = 1L;
or:
(SHORT)(*array++) = 1;
The first example is probably better.
If you don't want to change anythings, try using a lower warning level
(/w3 may be too high for this kind of operation). Or turn off
ANSI-compliant type-checking.
--
|) 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.205857.23557@njitgw.njit.edu>Path:
arc1-ca.pugleaf.net!sparky!uunet!cis.ohio-state.edu!pacific.mps.ohio-state.edu!linac!att!rutgers!njitgw.njit.edu!hertz.njit.edu!dic5340References:
<1992Aug28.154836.12867@natinst.com>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!sparky!uunet!cis.ohio-state.edu!pacific.mps.ohio-state.edu!linac!att!rutgers!njitgw.njit.edu!hertz.njit.edu!dic5340 From: dic5340@hertz.njit.edu (David Charlap) Newsgroups: comp.os.os2.programmer,comp.os.os2.apps,comp.os.os2.misc Subject: Re: C Set/2 Question in malloc Message-ID: <1992Aug28.205857.23557@njitgw.njit.edu> Date: 28 Aug 92 20:58:57 GMT References: <1992Aug28.154836.12867@natinst.com> Sender: news@njit.edu Organization: New Jersey Institute of Technology, Newark, N.J. Lines: 67 Nntp-Posting-Host: hertz.njit.edu