On Thu, Jul 15, 2010 at 6:08 PM, Dave Korn <dave.korn.cyg...@gmail.com> wrote: > On 16/07/2010 01:31, J Decker wrote: >> Oh not so bad then, I can just add at the beginning... >> >> typedef struct a *NeverUsedDefinition; >> >> and now it's happy? And that makes good coding how? > > No, that would be bad coding. Just forward-declare the tag: > > struct a; > > before you try and use it in a function's formal parameter list. > > The declarations in a function's formal parameter list are in a more inner > scope than file scope, so if there isn't a tag declaration at file scope yet, > you're talking about a new tag declaration limited only to the scope in which > it is declared - the function declaration (argument list and body, if present; > just argument list in the case of a prototype). > > When you later do declare a "struct a" tag at file scope, the later > definition of f() "inherits" that one from the more global scope, just like it > would "inherit" the name of a global variable from the enclosing scope. In > the C language spec: > > 6.7.2.3#4: "All declarations of structure, union, or enumerated types that > have the same scope and use the same tag declare the same type." > Then how does this result in the warnings even that type 'struct a' does not match target 'struct a'? (or some paraphrase of that, this sample code did not generate exactly the same warnings as the full project. How could two definitions of struct a be defined?
> 6.7.2.3#5: "Two declarations of structure, union, or enumerated types which > are in different scopes or use different tags declare distinct types." > Okay, and how is this out of scope? it's a global prototype, and the struct must without question also be defined in said global scope. When would it ever be something other than this? Although I did go back and read the error more appropriately. Okay I'm leaving this list. > > cheers, > DaveK > >