whose job is it to include various header files?

Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
From: Robert P. J. Day
Date: Thursday, March 13, 2008 - 3:09 pm

more a philosophy question than anything but, while poking around
the percpu stuff today, i noticed in the header file linux/percpu.h
the opening snippet:

 #include <linux/preempt.h>
 #include <linux/slab.h> /* For kmalloc() */
 #include <linux/smp.h>
 #include <linux/string.h> /* For memset() */
 #include <linux/cpumask.h>
 ...

hmmm, i thought to myself (because that's how i refer to myself), i
wonder why this header file is including headers for kmalloc() and
memset() when this header file makes no reference to those routines.
let's see what happens if i remove them and:

  $ make distclean
  $ make defconfig    [x86]
  $ make

=2E.. chug chug chug ...

  CC      arch/x86/kernel/nmi_32.o
arch/x86/kernel/nmi_32.c: In function =A1check_nmi_watchdog=A2:
arch/x86/kernel/nmi_32.c:81: error: implicit declaration of function =A1kma=
lloc=A2
arch/x86/kernel/nmi_32.c:81: error: =A1GFP_KERNEL=A2 undeclared (first use =
in this function)
arch/x86/kernel/nmi_32.c:81: error: (Each undeclared identifier is reported=
 only once
arch/x86/kernel/nmi_32.c:81: error: for each function it appears in.)
arch/x86/kernel/nmi_32.c:81: warning: assignment makes pointer from integer=
 without a cast
arch/x86/kernel/nmi_32.c:118: error: implicit declaration of function =A1kf=
ree=A2
make[1]: *** [arch/x86/kernel/nmi_32.o] Error 1
make: *** [arch/x86/kernel] Error 2
$

  ok, now i know.  but that means, of course, that nmi_32.c is
invoking kmalloc() without ever having included the necessary header
file for it -- it's just inheriting that from linux/percpu.h.

  doesn't that (sort of) violate the kernel coding style?  if a file
somewhere needs the contents of some header file, isn't it that file's
responsibility to explicitly include it, and not quietly realize it's
getting it from elsewhere?

rday
--


=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
Robert P. J. Day
Linux Consulting, Training and Annoying Kernel Pedantry:
    Have classroom, will lecture.

http://crashcourse.ca                          Waterloo, Ontario, CANADA
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
whose job is it to include various header files?, Robert P. J. Day, (Thu Mar 13, 3:09 pm)
Re: whose job is it to include various header files?, Randy Dunlap, (Thu Mar 13, 3:46 pm)
Re: whose job is it to include various header files?, Jesper Juhl, (Thu Mar 13, 4:53 pm)
Re: whose job is it to include various header files?, Robert P. J. Day, (Thu Mar 13, 6:02 pm)
Re: whose job is it to include various header files?, Jan Engelhardt, (Thu Mar 13, 6:36 pm)
Re: whose job is it to include various header files?, Robert P. J. Day, (Thu Mar 13, 6:53 pm)
Re: whose job is it to include various header files?, Alexey Dobriyan, (Thu Mar 13, 10:47 pm)
Re: whose job is it to include various header files?, Robert P. J. Day, (Fri Mar 14, 1:01 am)
Re: whose job is it to include various header files?, Robert P. J. Day, (Fri Mar 14, 1:07 am)
Re: whose job is it to include various header files?, Robert P. J. Day, (Fri Mar 14, 2:29 am)