Recursive #includes

Wayne A. Throop throopw at agarn.dg.com
Wed Mar 8 06:21:00 AEST 1989


> karl at haddock.ima.isc.com (Karl Heuer)
>> ka at june.cs.washington.edu (Kenneth Almquist)
>>I've been told that incomplete types cannot be used in function
>>prototypes.  For example,
>>	void f(struct s *);
>>	struct s { ... };
>>	void f(struct s *p) { ... }
>>is illegal ...
> Yes it is illegal, but due to a scoping problem, not a restriction against
> incomplete types.  Adding the empty declaration `struct s;' at the top should
> cause it to become legal.  (I just tested this with gcc.)

Testing it with DG C, this amusing, almost inscrutable, (though in
spirit quite correct) error message resulted:

    You have already declared "f" as a variable,
    enumeration, or typedef in the current block with different type
    attributes.  The following are the previous and current types:
            Previous type: void (struct s *)
            Current  type: void (struct s *)

Note, however, that incompleted types can still be used to break the
kinds of cycles I was talking about, since (as Karl points out) this
is a scoping problem not encountered in derivatives of the example I
gave.

--
"Is it an infinite loop?"
"I dunno... it sure is *persistent*, anyhow."
                              --- unknown
--
Wayne Throop      <the-known-world>!mcnc!rti!xyzzy!throopw



More information about the Comp.lang.c mailing list