home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #31 / NN_1992_31.iso / spool / comp / sys / amiga / programm / 18050 < prev    next >
Encoding:
Text File  |  1993-01-02  |  3.0 KB  |  102 lines

  1. Newsgroups: comp.sys.amiga.programmer
  2. Path: sparky!uunet!math.fu-berlin.de!informatik.tu-muenchen.de!rz.uni-passau.de!kirk.fmi.uni-passau.de!agsteine
  3. From: agsteine@kirk.fmi.uni-passau.de (Karlheinz Agsteiner)
  4. Subject: Re: A bug in SAS/C 6.0
  5. Message-ID: <1993Jan2.153715.1112@tom.rz.uni-passau.de>
  6. Sender: news@tom.rz.uni-passau.de (News-Operator)
  7. Organization: University of Passau, Germany
  8. References:  <1i29gdINN2he@mirror.digex.com>
  9. Date: Sat, 2 Jan 1993 15:37:15 GMT
  10. Lines: 90
  11.  
  12. In article <1i29gdINN2he@mirror.digex.com>, tstark@access.digex.com (Timothy M. Stark) writes:
  13. |> Hello Everyone:
  14.  
  15. Hi!
  16.  
  17. |> 
  18. |>       I discovered that bug in the compiler. I implemented a few typedef
  19. |> statements into my program and set up double-link variables. I tried compile 
  20. |> it but it displayed the strange message error:
  21. |> 
  22. |>       Missing closed bracket!
  23. |> 
  24. |> This bug program:
  25. |> 
  26. |> #include <stdio.h>
  27. |> 
  28. |> typedef struct bug1 {
  29. |>        bug2  *bugb;
  30. |> } bug1;
  31. |> 
  32. |> typedef struct bug2 {
  33. |>        bug1  *buga;
  34. |> } bug2;
  35.  
  36. IMHO, You're making two mistakes in Your declaration:
  37.  
  38. 1) You can't use the same name with Your struct and Your typedef.
  39.    (What You're doing is "typedef struct bug1 bug1"). Try struct _bug1
  40.    or something like that.
  41.  
  42. 2) I don't know where K&R are stating this, but I think You have to
  43.    define every type before using it. The only exception is a 
  44.    struct <name> *  where name doesn't need to be defined. Therefore
  45.    You should replace Your declaration by e.g.
  46.  
  47. typedef struct _bug1 {
  48.        struct _bug2 *bugb;
  49. } bug1;
  50.  
  51. typedef struct _bug2 {
  52.        struct _bug1 *buga;
  53. } bug2;
  54.  
  55. (which is how I implement crosswise linkings) or maybe
  56.  
  57. struct _bug1 { 
  58.   struct _bug2 *bugb;
  59. }
  60.  
  61. struct _bug2 {
  62.   struct _bug1 *buga;
  63. }
  64.  
  65. typedef struct _bug1 bug1;
  66. typedef struct _bug2 bug2;
  67.  
  68. These two declarations should work.
  69.  
  70. I think the compiler
  71.  
  72. |> This program cause the compiler confusing and it displayed the strange
  73. |> message - Missing closed bracket (']'). I looked for the open bracket
  74. |> character but it is not in my program! 
  75.  
  76. I don't know why the compiler complains about a "]". I think It "hits"
  77. the undeclared type "bug2", and thinks that this can't be probably part 
  78. of the type definition of "bug1", and therefore it should expect a "}"
  79. here to end the definition (hoping that "bug2" makes sense outside the
  80. definition.
  81.  
  82. Sorry for this permanent usage of both "type declaration" and 
  83. "type definition" for the same thing, but it seems that every
  84. language uses a different term for that :)
  85.  
  86. Hope this helps. I'm sure someone here has a much more K&R - like
  87. way to define the above, but I ran into the same problem as You
  88. defining crosswise dependencies, and this was the solution I found.
  89.  
  90. |> -- Tim Stark
  91. |> 
  92. |> 
  93. |> -- 
  94. |> Timothy Stark               Internet1: tstark@access.digex.com (Preferred)
  95. |> 837 North Van Dorn St       Internet2: tstark@netcom.com
  96. |> Alexandria, Va. 22304-2723  TDD: (703) 212-9731 Pager: (703) 702-4078
  97. |> "Washington, DC is the most deaf population!! -- Gallaudet University"
  98.  
  99. Karlheinz Agsteiner
  100. --
  101. e-mail: agsteine@kirk.fmi.uni-passau.de
  102.