home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #1 / NN_1993_1.iso / spool / comp / sys / amiga / programm / 18103 < prev    next >
Encoding:
Text File  |  1993-01-04  |  3.0 KB  |  101 lines

  1. Newsgroups: comp.sys.amiga.programmer
  2. Path: sparky!uunet!gatech!concert!sas!mozart.unx.sas.com!walker
  3. From: walker@twix.unx.sas.com (Doug Walker)
  4. Subject: Re: A bug in SAS/C 6.0
  5. Originator: walker@twix.unx.sas.com
  6. Sender: news@unx.sas.com (Noter of Newsworthy Events)
  7. Message-ID: <C0C43w.HLA@unx.sas.com>
  8. Date: Mon, 4 Jan 1993 14:55:07 GMT
  9. References:  <1i29gdINN2he@mirror.digex.com> <1993Jan2.153715.1112@tom.rz.uni-passau.de>
  10. Nntp-Posting-Host: twix.unx.sas.com
  11. Organization: SAS Institute Inc.
  12. Lines: 87
  13.  
  14.  
  15. In article <1993Jan2.153715.1112@tom.rz.uni-passau.de>, agsteine@kirk.fmi.uni-passau.de (Karlheinz Agsteiner) writes:
  16. |> 1) You can't use the same name with Your struct and Your typedef.
  17. |>    (What You're doing is "typedef struct bug1 bug1"). Try struct _bug1
  18. |>    or something like that.
  19.  
  20. This isn't true.  It's perfectly OK to use the same name as a structure
  21. tag and a typedef.
  22.  
  23. |> 2) I don't know where K&R are stating this, but I think You have to
  24. |>    define every type before using it. The only exception is a 
  25. |>    struct <name> *  where name doesn't need to be defined. Therefore
  26.  
  27. This *is* true.
  28.  
  29. |>    You should replace Your declaration by e.g.
  30. |> 
  31. |> typedef struct _bug1 {
  32. |>        struct _bug2 *bugb;
  33. |> } bug1;
  34. |> 
  35. |> typedef struct _bug2 {
  36. |>        struct _bug1 *buga;
  37. |> } bug2;
  38. |> 
  39. |> (which is how I implement crosswise linkings) or maybe
  40. |> 
  41. |> struct _bug1 { 
  42. |>   struct _bug2 *bugb;
  43. |> }
  44. |> 
  45. |> struct _bug2 {
  46. |>   struct _bug1 *buga;
  47. |> }
  48. |> 
  49. |> typedef struct _bug1 bug1;
  50. |> typedef struct _bug2 bug2;
  51.  
  52. The following also works, although it looks strange:
  53.  
  54. typedef struct bug2 bug2;  // Use struct bug2 without defining it
  55.  
  56. typedef struct bug1
  57. {
  58.    bug2 *bugb;
  59. } *bug1;
  60.  
  61. struct bug2                // NOW go ahead and define struct bug2
  62. {
  63.    bug1 *buga;
  64. };
  65.  
  66. |> |> This program cause the compiler confusing and it displayed the strange
  67. |> |> message - Missing closed bracket (']'). I looked for the open bracket
  68. |> |> character but it is not in my program! 
  69. |> 
  70. |> I don't know why the compiler complains about a "]". I think It "hits"
  71.  
  72. It doesn't.  It complains about a "close brace expected".  A brace is
  73. a }, not a ].
  74.  
  75. |> the undeclared type "bug2", and thinks that this can't be probably part 
  76. |> of the type definition of "bug1", and therefore it should expect a "}"
  77. |> here to end the definition (hoping that "bug2" makes sense outside the
  78. |> definition.
  79.  
  80. Exactly.
  81.  
  82. |> Hope this helps. I'm sure someone here has a much more K&R - like
  83. |> way to define the above, but I ran into the same problem as You
  84. |> defining crosswise dependencies, and this was the solution I found.
  85.  
  86. The above method is supported by ANSI, but (I think) not by pre-ANSI K&R.
  87.  
  88. |> |> -- Tim Stark
  89.  
  90. |> Karlheinz Agsteiner
  91.  
  92. -- 
  93.   *****
  94. =*|_o_o|\\=====Doug Walker, Software Distiller====== BBS: (919)460-7430 =
  95.  *|. o.| ||                                          1200/2400/9600 Dual
  96.   | o  |//     For all you do, this bug's for you!
  97.   ====== 
  98. usenet: walker@unx.sas.com                            bix: djwalker 
  99. Any opinions expressed are mine, not those of SAS Institute, Inc.
  100.  
  101.