linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
* QUERY: Inclusion of header files in kernel header files.
@ 2010-02-23  6:30 viresh kumar
  2010-02-24  2:52 ` Eric Miao
  0 siblings, 1 reply; 5+ messages in thread
From: viresh kumar @ 2010-02-23  6:30 UTC (permalink / raw)
  To: linux-arm-kernel

Hello,

I have been through many kernel header files and have found that kernel
header
files at many places don't include other header files which they have
dependency upon.

For example:
<linux/amba/bus.h> uses struct device and struct resource and it doesn't
include <linux/device.h> and <linux/resource.h> header files.

Now, whenever i try to include bus.h, i have to include device.h and
resource.h.

Is this correct approach?

Again, if i include device.h and resource.h, they must be included before
bus.h.
Now this will disturb the alphabetical ordering of including header files
sometimes. (not in this example)

Any idea behind this philosophy.


regards,
viresh kumar
ST Microelectronics
India.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20100223/a3ce48a3/attachment.htm>

^ permalink raw reply	[flat|nested] 5+ messages in thread

* QUERY: Inclusion of header files in kernel header files.
@ 2010-02-23  6:36 viresh kumar
  0 siblings, 0 replies; 5+ messages in thread
From: viresh kumar @ 2010-02-23  6:36 UTC (permalink / raw)
  To: linux-arm-kernel

Hello,

I have been through many kernel header files and have found that kernel
header
files at many places don't include other header files which they have
dependency upon.

For example:
<linux/amba/bus.h> uses struct device and struct resource and it doesn't
include <linux/device.h> and <linux/resource.h> header files.

Now, whenever i try to include bus.h, i have to include device.h and
resource.h.

Is this correct approach?

Again, if i include device.h and resource.h, they must be included before
bus.h.
Now this will disturb the alphabetical ordering of including header files
sometimes. (not in this example)

Any idea behind this philosophy.


regards,
viresh kumar
ST Microelectronics
India.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20100223/8f5cac70/attachment.htm>

^ permalink raw reply	[flat|nested] 5+ messages in thread

* QUERY: Inclusion of header files in kernel header files.
  2010-02-23  6:30 viresh kumar
@ 2010-02-24  2:52 ` Eric Miao
  2010-02-24  4:20   ` viresh kumar
  0 siblings, 1 reply; 5+ messages in thread
From: Eric Miao @ 2010-02-24  2:52 UTC (permalink / raw)
  To: linux-arm-kernel

On Tue, Feb 23, 2010 at 2:30 PM, viresh kumar <viresh.linux@gmail.com> wrote:
> Hello,
> I have been through many kernel header files and have found that kernel
> header
> files at many places don't include other header files which they have
> dependency upon.
> For example:
> <linux/amba/bus.h> uses struct device and struct resource and it doesn't
> include <linux/device.h> and <linux/resource.h> header files.
> Now, whenever i try to include bus.h, i have to include device.h and
> resource.h.
> Is this correct approach?
> Again, if i include device.h and resource.h, they must be included before
> bus.h.
> Now this will disturb the alphabetical ordering of including header files
> sometimes. (not in this example)
> Any idea behind this philosophy.
>

My understanding is that if you are going to include every dependency
into the header files, they are going to explode very soon. E.g. like bus.h,
as long as you declared something like:

struct device;
struct resource;

....

The compiler will be happy to know the structures are actually defined
elsewhere when processing the header file itself (as long as there is
no direct de-reference of the field members of these structures). And
thus in .c file you are going to decide all the dependent header files
by your own.

> regards,
> viresh kumar
> ST Microelectronics
> India.
> _______________________________________________
> linux-arm-kernel mailing list
> linux-arm-kernel at lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
>
>

^ permalink raw reply	[flat|nested] 5+ messages in thread

* QUERY: Inclusion of header files in kernel header files.
  2010-02-24  2:52 ` Eric Miao
@ 2010-02-24  4:20   ` viresh kumar
  2010-02-24 12:59     ` Laurent Pinchart
  0 siblings, 1 reply; 5+ messages in thread
From: viresh kumar @ 2010-02-24  4:20 UTC (permalink / raw)
  To: linux-arm-kernel

> My understanding is that if you are going to include every dependency
> into the header files, they are going to explode very soon. E.g. like bus.h,
> as long as you declared something like:
>
> struct device;
> struct resource;
>

If these two structure prototypes are already present in latest kernel
then its okay.
Actually i have seen 2.6.32 and these prototypes are not present
there, so we may need to add
header file or add prototypes of these structures.

rgds,
viresh.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* QUERY: Inclusion of header files in kernel header files.
  2010-02-24  4:20   ` viresh kumar
@ 2010-02-24 12:59     ` Laurent Pinchart
  0 siblings, 0 replies; 5+ messages in thread
From: Laurent Pinchart @ 2010-02-24 12:59 UTC (permalink / raw)
  To: linux-arm-kernel

Hi Viresh,

On Wednesday 24 February 2010 05:20:59 viresh kumar wrote:
> > My understanding is that if you are going to include every dependency
> > into the header files, they are going to explode very soon. E.g. like
> > bus.h, as long as you declared something like:
> > 
> > struct device;
> > struct resource;
> 
> If these two structure prototypes are already present in latest kernel
> then its okay.
> Actually i have seen 2.6.32 and these prototypes are not present
> there, so we may need to add header file or add prototypes of these
> structures.

As a rule of thumb, header files should use forward-declaration of structures 
whenever possible. Including other header files to pull in structure 
definitions is only required when embedding a structure into another (as the 
compiler needs to known the embedded structure size) and when inline functions 
or macros dereference pointers to the structure (although in the case of 
macros there's not strict requirement).

Exceptions to this rule are of course permitted.

-- 
Regards,

Laurent Pinchart

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2010-02-24 12:59 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-02-23  6:36 QUERY: Inclusion of header files in kernel header files viresh kumar
  -- strict thread matches above, loose matches on Subject: below --
2010-02-23  6:30 viresh kumar
2010-02-24  2:52 ` Eric Miao
2010-02-24  4:20   ` viresh kumar
2010-02-24 12:59     ` Laurent Pinchart

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).