home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #19 / NN_1992_19.iso / spool / comp / lang / c / 13149 < prev    next >
Encoding:
Internet Message Format  |  1992-09-02  |  1.6 KB

  1. Path: sparky!uunet!decwrl!nntp1.radiomail.net!fernwood!synopsys!news.synopsys.com!jerry
  2. From: jerry@synopsys.com (Jerry Huth)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: pointer to araay of structs
  5. Keywords: pointers
  6. Message-ID: <1992Sep2.003355.29404@Synopsys.Com>
  7. Date: 2 Sep 92 00:33:55 GMT
  8. References: <BtICrz.5pB@orfeo.radig.de>
  9. Sender: usenet@Synopsys.Com
  10. Organization: Synopsys Inc.
  11. Lines: 44
  12.  
  13. eric@orfeo.radig.de (Eric Tuerlings) writes:
  14.  
  15. >> struct aaa {
  16. >>     char y;
  17. >>     char z;
  18. >> } ;
  19. >> 
  20. >> void func (struct aaa (*bbb)[])
  21. >> {
  22. >>     char z;
  23. >> 
  24. >>     z = bbb[3]->z;
  25. >> }
  26. >> 
  27. >> in which bbb is a pointer to an array of aaa structures. The compiler
  28. >> complains about an unknown size.
  29.  
  30. Your parameter declaration "struct aaa (*bbb)[]" is indeed a pointer
  31. to an array of aaa structures, but your use of it "z = bbb[3]->z;"
  32. tries to access it as if bbb is an array of pointers to aaa
  33. structures.  So, the compiler is correct in complaining.
  34.  
  35. You can do any of the following:
  36.  
  37.   1) bbb is a pointer to an array of aaa structures
  38.  
  39.      decl:  struct aaa (*bbb)[]
  40.      use:   z = (*bbb)[3].z ;        <- new use
  41.  
  42.   2) bbb is an array of pointers to aaa structures
  43.  
  44.      decl:  struct aaa *(bbb[])      <- new decl
  45.      use:   z = bbb[3]->z ;
  46.  
  47. But, it may be that BOTH your use and your decl are wrong, and
  48. what you really want is:
  49.  
  50.   3) bbb is an array of aaa structures
  51.  
  52.      decl:  struct aaa bbb[]         <- new decl
  53.      use:   z = bbb[3].z             <- new use
  54.  
  55. (Note to goldstei@cgi.com ("Morris Goldstein"): This is definitely
  56. an example of one of the most confusing things about C!)
  57.