RE: [PATCH 1/7] drivers: usb: Include appropriate header file in hcd.c
From: David Laight
Date: Fri Dec 20 2013 - 04:41:43 EST
> From: Josh Triplett
> On Thu, Dec 19, 2013 at 05:33:09PM -0000, David Laight wrote:
> > OTOH just including extra headers isn't ideal - it can considerably
> > slow down the compilation time. There are many subsystems that don't
> > really separate their internal headers from their external ones.
>
> There's a benefit to doing so, though: it ensures that the prototypes in
> the header stay in sync with the definition.
I think you misunderstood what I was saying.
The header with the function prototypes has to be included when the
driver itself is built - there is a gcc warning for that as well.
The 'problem' is that if I only have:
void foo(struct foo *);
then the C language (uselessly) scopes the declaration of 'struct foo'
to the inside of the functions - making it almost impossible to call.
All you need is an outer declaration:
struct foo;
void foo(struct foo *);
what you don't need is the actual definition of 'struct foo'.
Source files that need to look at the members of the structure
should be directly including the header that defines the structure.
Adding nested includes just makes it more likely that code will fail
to directly include the headers that define the structures it uses.
David
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/