Help on casting arrays

Shiping Zhang ping at cubmol.bio.columbia.edu
Fri Feb 2 01:49:35 AEST 1990


In article <1990Jan31.165428.2538 at cubmol.bio.columbia.edu> ping at cubmol.bio.columbia.edu (Shiping Zhang) writes:
>In article <931 at christopher-robin.cs.bham.ac.uk> cjr at uk.ac.bham.cs (Chris Ridd <RiddCJ>) writes:
>>I have the following declarations in an image enhancing program:
  
>>typedef unsigned char u_char;
>>char ang[512][512];
> ^^^^
>ang is declared as char instead u_char.
 
>>void imgsave(char *filename, u_char img[512][512])
>>{
>>...
>>}
  
>>  imgsave("filename", ang);
  
>>The GCC compiler gives (correctly) a warning on the imgsave call, saying
>>incompatible pointer types (or something similar).  What should the cast be
>>to correct this?  I have tried:
>>(u_char (*)[512][512])ang,
>>((u_char *)[512][512])ang,
>>     etc...
  
 
>The casting should be following:
 
> u_char (*img)[512]

Someone pointed out to me that it is a declare instead of cast.
He is right.  The cast should be

    (u_char (*)[512])img

Sorry for the wrong information.

By the way, the problem of the original poster is probably caused
by declaring ang as char instead u_char, unless it is the auther's
intention. It is not necessary to cast ang when it is used as the
second argument of imgsave() if the declaration is consistant.

>-ping

-ping



More information about the Comp.lang.c mailing list