Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!wuarchive!uunet!taumet!steve From: steve@taumet.com (Stephen Clamage) Newsgroups: comp.std.c Subject: Re: Pointers to Incomplete Types in Prototypes Message-ID: <709@taumet.com> Date: 4 May 91 18:28:39 GMT References: <700@taumet.com> <683g+p#@rpi.edu> Organization: Taumetric Corporation, San Diego Lines: 47 xor@aix01.aix.rpi.edu (Joseph Schwartz) writes: >But I still have a hard time believing that it applies to struct bar in: > extern void foo(struct bar *); >Making bar have local scope in this case is of questionable usefulness, >and it would appear to break code that existed before the Standard. I agree it is not useful to write code this way. But code before the standard did not use prototypes -- they were introduced by the standard (borrowing from C++). So what previously-correct code can be broken? The only alternative is to promote the declaration in a function prototype to some outer scope. To which scope? Always to file scope? Just to the enclosing scope? Consider: void f1() { extern void f2( void (*)(struct bar*) ); ... } Here, f2 takes a parameter which is a pointer to a function which takes a parameter of type struct bar. If no declaration for struct bar appears before this, what is the scope of struct bar? The ANSI rules provide a completely consistent interpretation of these issues. In the absence of a corresponding declaration in an enclosing scope, the scope of a declaration in a prototype parameter list ends with the prototype. If you mean for it to refer to a declaration in an enclosing scope, the declaration must be visible. This too is a uniform rule: you must declare a type before you can use it. >Then why does this: > struct bar; > extern void foo(struct bar *); >solve the scoping problems? Because of the uniform scoping rules throughout the standard. The first declaration of struct bar is in a scope which encloses the prototype scope, and there is no other declaration to hide it. Therefore, the struct bar in the prototype must refer to the same type as the first. The point you seem to be missing is that the parameter list in a function prototype not part of a function definition has its own scope. -- Steve Clamage, TauMetric Corp, steve@taumet.com