Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!rutgers!columbia!cubmol!ping From: ping@cubmol.bio.columbia.edu (Shiping Zhang) Newsgroups: comp.lang.c Subject: Re: Help on casting arrays Keywords: casts Message-ID: <1990Feb1.144935.8651@cubmol.bio.columbia.edu> Date: 1 Feb 90 14:49:35 GMT References: <931@christopher-robin.cs.bham.ac.uk> <1990Jan31.165428.2538@cubmol.bio.columbia.edu> Reply-To: ping@cubmol.bio.columbia.edu (Shiping Zhang) Organization: Dept. of Biology, Columbia Univ., New York, NY Lines: 43 In article <1990Jan31.165428.2538@cubmol.bio.columbia.edu> ping@cubmol.bio.columbia.edu (Shiping Zhang) writes: >In article <931@christopher-robin.cs.bham.ac.uk> cjr@uk.ac.bham.cs (Chris Ridd ) 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