On Mon, 21 Feb 2005, Shae Tan wrote:

> Hello everybody,
> Can you help me with this (I know there are very good C programmers 
here):
>
> FILE *stream;
>       int inputArraySize;
>       int *inputLengthArray;
>       int *inputDirectionArray;
>
>       stream = fopen("db.txt","rt");
>
>       fscanf(stream, "%d\n", &inputArraySize);
>
> // this is line 24
>       inputLengthArray = calloc(inputArraySize, sizeof(int));
> // this is line 25
>       inputDirectionArray = calloc(inputArraySize, sizeof(int));
>
>       fclose(stream);
>
> The compiler (GCC) reports the following warnings:
> 24: warning: assignment makes pointer from integer without a cast
> 25: warning: assignment makes pointer from integer without a cast


if(inputArraySize>0) {
  if( !(inputLengthArray = (int*) calloc(inputArraySize, sizeof(int))) ) 
     return -ENOMEM;
  
  if( !(inputDirectionArray = (int*) calloc(inputArraySize, sizeof(int))) 
    {
     free(inputLengthArray);
     return -ENOMEM;
    }
}

...

free(inputDirectionArray);
free(inputLengthArray);

since calloc() returns void* which must be type casted to a proper pointer
to a valid data type.

rowel

--
Philippine Linux Users' Group (PLUG) Mailing List
[email protected] (#PLUG @ irc.free.net.ph)
Official Website: http://plug.linux.org.ph
Searchable Archives: http://marc.free.net.ph
.
To leave, go to http://lists.q-linux.com/mailman/listinfo/plug
.
Are you a Linux newbie? To join the newbie list, go to
http://lists.q-linux.com/mailman/listinfo/ph-linux-newbie

Reply via email to