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." 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." cheers, DaveK