home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!decwrl!nntp1.radiomail.net!fernwood!synopsys!news.synopsys.com!jerry
- From: jerry@synopsys.com (Jerry Huth)
- Newsgroups: comp.lang.c
- Subject: Re: pointer to araay of structs
- Keywords: pointers
- Message-ID: <1992Sep2.003355.29404@Synopsys.Com>
- Date: 2 Sep 92 00:33:55 GMT
- References: <BtICrz.5pB@orfeo.radig.de>
- Sender: usenet@Synopsys.Com
- Organization: Synopsys Inc.
- Lines: 44
-
- eric@orfeo.radig.de (Eric Tuerlings) writes:
-
- >> struct aaa {
- >> char y;
- >> char z;
- >> } ;
- >>
- >> void func (struct aaa (*bbb)[])
- >> {
- >> char z;
- >>
- >> z = bbb[3]->z;
- >> }
- >>
- >> in which bbb is a pointer to an array of aaa structures. The compiler
- >> complains about an unknown size.
-
- Your parameter declaration "struct aaa (*bbb)[]" is indeed a pointer
- to an array of aaa structures, but your use of it "z = bbb[3]->z;"
- tries to access it as if bbb is an array of pointers to aaa
- structures. So, the compiler is correct in complaining.
-
- You can do any of the following:
-
- 1) bbb is a pointer to an array of aaa structures
-
- decl: struct aaa (*bbb)[]
- use: z = (*bbb)[3].z ; <- new use
-
- 2) bbb is an array of pointers to aaa structures
-
- decl: struct aaa *(bbb[]) <- new decl
- use: z = bbb[3]->z ;
-
- But, it may be that BOTH your use and your decl are wrong, and
- what you really want is:
-
- 3) bbb is an array of aaa structures
-
- decl: struct aaa bbb[] <- new decl
- use: z = bbb[3].z <- new use
-
- (Note to goldstei@cgi.com ("Morris Goldstein"): This is definitely
- an example of one of the most confusing things about C!)
-