Jump to content
Search In
  • More options...
Find results that contain...
Find results in...
Sign in to follow this  
Quasar

GCC warning

Recommended Posts

If I have a previously undeclared structure type as a function parameter, as such:

void P_CheckLevel(struct waddir_s *dir, ...);
GCC gives this warning at the point of declaration in every file including the header:
p_setup.h:40: warning: 'struct waddir_s' declared inside parameter list
p_setup.h:40: warning: its scope is only this definition or declaration, which is probably not what you want
And then it further says this at the point of every call:
g_cmd.c: In function 'Handler_map':
g_cmd.c:365: warning: passing argument 1 of 'P_CheckLevel' from incompatible pointer type
First of all, since when is "struct foo *" a declaration of a structure type? Second of all, since when do function parameters serve as declarators? And third of all, how the fuck do I fix this other than by including headers into headers and causing header hell to worsen even further?

Share this post


Link to post

In my experience doing that in C causes a "conflicting definition of type" warning or error if the "real" definition of the structure comes into the same scope.

Share this post


Link to post

From the GCC manual:

   * Users often think it is a bug when GCC reports an error for code
     like this:

          int foo (struct mumble *);

          struct mumble { ... };

          int foo (struct mumble *x)
          { ... }

     This code really is erroneous, because the scope of `struct
     mumble' in the prototype is limited to the argument list
     containing it.  It does not refer to the `struct mumble' defined
     with file scope immediately below--they are two unrelated types
     with similar names in different scopes.

     But in the definition of `foo', the file-scope type is used
     because that is available to be inherited.  Thus, the definition
     and the prototype do not match, and you get an error.

     This behavior may seem silly, but it's what the ISO standard
     specifies.  It is easy enough for you to make your code work by
     moving the definition of `struct mumble' above the prototype.
     It's not worth being incompatible with ISO C just to avoid an
     error for the example shown above.

Share this post


Link to post

How retarded...

If it always was that easy to have the struct's declaration available. Whoever cooked this specs up deserves to be sent to hell for all eternity...

Share this post


Link to post

*shrug* isn't that one of the reasons why structs should be typedef'ed and placed in header files? Don't try to find design elegancy or lack of convolution in plain C...

Share this post


Link to post

That's easier said than done if you'd like to avoid header dependency hell.

In C++ it's fortunately possible to declare a struct anonymously which resolves the entire mess.

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  
×