All of lore.kernel.org
 help / color / mirror / Atom feed
* including .c files ?
@ 2008-08-08 11:25 Frans Meulenbroeks
  2008-08-08 14:30 ` Krzysztof Halasa
  2008-08-08 15:36 ` Rene Herman
  0 siblings, 2 replies; 6+ messages in thread
From: Frans Meulenbroeks @ 2008-08-08 11:25 UTC (permalink / raw)
  To: linux-kernel

[-- Attachment #1: Type: text/plain, Size: 927 bytes --]

I was wondering how people feel about including .c files in other .c files.

I saw a few occasions of this.
Triggered by that observation I decided to do a grep for this (on
2.6.25.7 as that was the one I had handy at that moment).
Some 268 .c files are included.
Seems an awful lot for me.

Do people feel this is good practice?
I understand that sometimes it is useful (and then you might need to
decide on whether to include a .c file or to have a .h file with
code), but in other places it is probably less relevant.

Generally I would expect that if the .c file contains some standalone
functionality then it should probably be a .c file on its own with a
well defined interface.

Curious what others think about this.
As attachement I've added the output of the grep (slightly edited to
remove some false positives, like those from the Documentation and
scripts directories and those who are obviously comments).

Frans.

[-- Attachment #2: C_INC.txt --]
[-- Type: text/plain, Size: 14727 bytes --]

./arch/alpha/boot/misc.c:#include "../../../lib/inflate.c"
./arch/arm/boot/compressed/misc.c:#include "../../../../lib/inflate.c"
./arch/cris/arch-v10/boot/compressed/misc.c:#include "../../../../../lib/inflate.c"
./arch/cris/arch-v32/boot/compressed/misc.c:#include "../../../../../lib/inflate.c"
./arch/h8300/boot/compressed/misc.c:#include "../../../../lib/inflate.c"
./arch/ia64/ia32/binfmt_elf32.c:#include "../../../fs/binfmt_elf.c"
./arch/ia64/kernel/unwind.c:#include "unwind_decoder.c"
./arch/m32r/boot/compressed/misc.c:#include "m32r_sio.c"
./arch/m32r/boot/compressed/misc.c:#include "../../../../lib/inflate.c"
./arch/mips/kernel/binfmt_elfn32.c:#include "../../../fs/binfmt_elf.c"
./arch/mips/kernel/binfmt_elfo32.c:#include "../../../fs/binfmt_elf.c"
./arch/mn10300/boot/compressed/misc.c:#include "../../../../lib/inflate.c"
./arch/parisc/kernel/binfmt_elf32.c:#include "../../../fs/binfmt_elf.c"
./arch/ppc/boot/lib/kbd.c:#include "defkeymap.c"	/* yeah I know it's bad -- Cort */
./arch/s390/kernel/binfmt_elf32.c:#include "../../../fs/binfmt_elf.c"
./arch/sh/boot/compressed/misc_32.c:#include "../../../../lib/inflate.c"
./arch/sh/boot/compressed/misc_64.c:#include "../../../../lib/inflate.c"
./arch/x86/boot/compressed/misc.c:#include "../../../../lib/inflate.c"
./arch/x86/boot/mkcpustr.c:#include "../kernel/cpu/feature_names.c"
./arch/x86/kernel/asm-offsets.c:# include "asm-offsets_32.c"
./arch/x86/kernel/asm-offsets.c:# include "asm-offsets_64.c"
./arch/x86/mm/pageattr.c:#include "pageattr-test.c"
./drivers/atm/nicstar.c:#include "nicstarmac.c"
./drivers/block/cciss.c:#include "cciss_scsi.c"		/* For SCSI tape support */
./drivers/block/paride/bpck6.c:#include "ppc6lnx.c"
./drivers/char/ip2/ip2main.c:#include "i2ellis.c"    /* Extremely low-level interface services */
./drivers/char/ip2/ip2main.c:#include "i2cmd.c"      /* Standard loadware command definitions */
./drivers/char/ip2/ip2main.c:#include "i2lib.c"      /* High level interface services */
./drivers/isdn/hardware/eicon/capifunc.c:#include "debuglib.c"
./drivers/isdn/hardware/eicon/dadapter.c:#include "debuglib.c"
./drivers/isdn/hardware/eicon/divasfunc.c:#include "debuglib.c"
./drivers/isdn/hardware/eicon/idifunc.c:#include "debuglib.c"
./drivers/isdn/hardware/eicon/mntfunc.c:#include "debuglib.c"
./drivers/isdn/hisax/asuscom.c:#include "hscx_irq.c"
./drivers/isdn/hisax/avm_a1.c:#include "hscx_irq.c"
./drivers/isdn/hisax/avm_a1p.c:#include "hscx_irq.c"
./drivers/isdn/hisax/bkm_a4t.c:#include "jade_irq.c"
./drivers/isdn/hisax/bkm_a8.c:#include "hscx_irq.c"
./drivers/isdn/hisax/diva.c:#include "hscx_irq.c"
./drivers/isdn/hisax/elsa.c:#include "elsa_ser.c"
./drivers/isdn/hisax/elsa.c:#include "hscx_irq.c"
./drivers/isdn/hisax/gazel.c:#include "hscx_irq.c"
./drivers/isdn/hisax/ix1_micro.c:#include "hscx_irq.c"
./drivers/isdn/hisax/mic.c:#include "hscx_irq.c"
./drivers/isdn/hisax/niccy.c:#include "hscx_irq.c"
./drivers/isdn/hisax/s0box.c:#include "hscx_irq.c"
./drivers/isdn/hisax/saphir.c:#include "hscx_irq.c"
./drivers/isdn/hisax/sedlbauer.c:#include "hscx_irq.c"
./drivers/isdn/hisax/sportster.c:#include "hscx_irq.c"
./drivers/isdn/hisax/teles0.c:#include "hscx_irq.c"
./drivers/isdn/hisax/teles3.c:#include "hscx_irq.c"
./drivers/isdn/hisax/telespci.c:#include "hscx_irq.c"
./drivers/message/i2o/config-osm.c:#include "i2o_config.c"
./drivers/net/8390.c:#include "lib8390.c"
./drivers/net/arm/etherh.c:#include "../lib8390.c"
./drivers/net/ax88796.c:#include "lib8390.c"
./drivers/net/hydra.c:#include "lib8390.c"
./drivers/net/jazzsonic.c:#include "sonic.c"
./drivers/net/lasi_82596.c:#include "lib82596.c"
./drivers/net/mac8390.c:#include "lib8390.c"
./drivers/net/macsonic.c:#include "sonic.c"
./drivers/net/ne-h8300.c:#include "lib8390.c"
./drivers/net/pcmcia/ibmtr_cs.c:#include "../tokenring/ibmtr.c"
./drivers/net/sk98lin/skgepnmi.c:#include "skgemib.c"
./drivers/net/sni_82596.c:#include "lib82596.c"
./drivers/net/wan/c101.c:#include "hd6457x.c"
./drivers/net/wan/n2.c:#include "hd6457x.c"
./drivers/net/wan/pc300too.c:#include "hd6457x.c"
./drivers/net/wan/pci200syn.c:#include "hd6457x.c"
./drivers/net/wireless/hostap/hostap_cs.c:#include "hostap_hw.c"
./drivers/net/wireless/hostap/hostap_hw.c:#include "hostap_download.c"
./drivers/net/wireless/hostap/hostap_hw.c:#include "hostap_callback.c"
./drivers/net/wireless/hostap/hostap_pci.c:#include "hostap_hw.c"
./drivers/net/wireless/hostap/hostap_plx.c:#include "hostap_hw.c"
./drivers/net/zorro8390.c:#include "lib8390.c"
./drivers/scsi/a2091.c:#include "scsi_module.c"
./drivers/scsi/a3000.c:#include "scsi_module.c"
./drivers/scsi/aha1542.c:#include "scsi_module.c"
./drivers/scsi/aic7xxx_old.c:#include "aic7xxx_old/aic7xxx_seq.c"
./drivers/scsi/aic7xxx_old.c:#include "aic7xxx_old/aic7xxx_proc.c"
./drivers/scsi/aic7xxx_old.c:#include "scsi_module.c"
./drivers/scsi/arm/cumana_1.c:#include "../NCR5380.c"
./drivers/scsi/arm/oak.c:#include "../NCR5380.c"
./drivers/scsi/atari_scsi.c:#include "atari_dma_emul.c"
./drivers/scsi/atari_scsi.c:#include "atari_NCR5380.c"
./drivers/scsi/atari_scsi.c:#include "scsi_module.c"
./drivers/scsi/BusLogic.c:#include "FlashPoint.c"
./drivers/scsi/dmx3191d.c:#include "NCR5380.c"
./drivers/scsi/dpt_i2o.c:#include "scsi_module.c"
./drivers/scsi/dtc.c:#include "NCR5380.c"
./drivers/scsi/dtc.c:#include "scsi_module.c"
./drivers/scsi/eata.c:#include "scsi_module.c"
./drivers/scsi/eata_pio.c:#include "scsi_module.c"
./drivers/scsi/fdomain.c:#include "scsi_module.c"
./drivers/scsi/fd_mcs.c:#include "scsi_module.c"
./drivers/scsi/gdth.c:#include "gdth_proc.c"
./drivers/scsi/gvp11.c:#include "scsi_module.c"
./drivers/scsi/g_NCR5380.c:#include "NCR5380.c"
./drivers/scsi/g_NCR5380.c:#include "scsi_module.c"
./drivers/scsi/g_NCR5380_mmio.c:#include "g_NCR5380.c"
./drivers/scsi/in2000.c:#include "scsi_module.c"
./drivers/scsi/mac_scsi.c:#include "NCR5380.c"
./drivers/scsi/mac_scsi.c:#include "scsi_module.c"
./drivers/scsi/mvme147.c:#include "scsi_module.c"
./drivers/scsi/NCR53c406a.c:#include "scsi_module.c"
./drivers/scsi/nsp32.c:# include "nsp32_debug.c"
./drivers/scsi/pas16.c:#include "NCR5380.c"
./drivers/scsi/pas16.c:#include "scsi_module.c"
./drivers/scsi/pcmcia/aha152x_core.c:#include "aha152x.c"
./drivers/scsi/pcmcia/fdomain_core.c:#include "fdomain.c"
./drivers/scsi/pcmcia/nsp_cs.c:#include "nsp_message.c"
./drivers/scsi/pcmcia/nsp_cs.c:#include "nsp_debug.c"
./drivers/scsi/qlogicpti.c:#include "qlogicpti_asm.c"
./drivers/scsi/sun3_scsi.c:#include "sun3_NCR5380.c"
./drivers/scsi/sun3_scsi.c:#include "scsi_module.c"
./drivers/scsi/sun3_scsi_vme.c:#include "sun3_NCR5380.c"
./drivers/scsi/sun3_scsi_vme.c:#include "scsi_module.c"
./drivers/scsi/sym53c416.c:#include "scsi_module.c"
./drivers/scsi/t128.c:#include "NCR5380.c"
./drivers/scsi/t128.c:#include "scsi_module.c"
./drivers/scsi/u14-34f.c:#include "scsi_module.c"
./drivers/scsi/ultrastor.c:#include "scsi_module.c"
./drivers/scsi/wd7000.c:#include "scsi_module.c"
./drivers/usb/host/ehci-hcd.c:#include "ehci-dbg.c"
./drivers/usb/host/ehci-hcd.c:#include "ehci-hub.c"
./drivers/usb/host/ehci-hcd.c:#include "ehci-mem.c"
./drivers/usb/host/ehci-hcd.c:#include "ehci-q.c"
./drivers/usb/host/ehci-hcd.c:#include "ehci-sched.c"
./drivers/usb/host/ehci-hcd.c:#include "ehci-pci.c"
./drivers/usb/host/ehci-hcd.c:#include "ehci-fsl.c"
./drivers/usb/host/ehci-hcd.c:#include "ehci-au1xxx.c"
./drivers/usb/host/ehci-hcd.c:#include "ehci-ps3.c"
./drivers/usb/host/ehci-hcd.c:#include "ehci-ppc-soc.c"
./drivers/usb/host/ehci-hcd.c:#include "ehci-ppc-of.c"
./drivers/usb/host/ehci-hcd.c:#include "ehci-orion.c"
./drivers/usb/host/ehci-hcd.c:#include "ehci-ixp4xx.c"
./drivers/usb/host/ohci-hcd.c:#include "ohci-hub.c"
./drivers/usb/host/ohci-hcd.c:#include "ohci-dbg.c"
./drivers/usb/host/ohci-hcd.c:#include "ohci-mem.c"
./drivers/usb/host/ohci-hcd.c:#include "ohci-q.c"
./drivers/usb/host/ohci-hcd.c:#include "ohci-pci.c"
./drivers/usb/host/ohci-hcd.c:#include "ohci-sa1111.c"
./drivers/usb/host/ohci-hcd.c:#include "ohci-s3c2410.c"
./drivers/usb/host/ohci-hcd.c:#include "ohci-omap.c"
./drivers/usb/host/ohci-hcd.c:#include "ohci-lh7a404.c"
./drivers/usb/host/ohci-hcd.c:#include "ohci-pxa27x.c"
./drivers/usb/host/ohci-hcd.c:#include "ohci-ep93xx.c"
./drivers/usb/host/ohci-hcd.c:#include "ohci-au1xxx.c"
./drivers/usb/host/ohci-hcd.c:#include "ohci-pnx8550.c"
./drivers/usb/host/ohci-hcd.c:#include "ohci-ppc-soc.c"
./drivers/usb/host/ohci-hcd.c:#include "ohci-at91.c"
./drivers/usb/host/ohci-hcd.c:#include "ohci-pnx4008.c"
./drivers/usb/host/ohci-hcd.c:#include "ohci-sh.c"
./drivers/usb/host/ohci-hcd.c:#include "ohci-ppc-of.c"
./drivers/usb/host/ohci-hcd.c:#include "ohci-ps3.c"
./drivers/usb/host/ohci-hcd.c:#include "ohci-ssb.c"
./drivers/usb/host/ohci-hcd.c:#include "ohci-sm501.c"
./drivers/usb/host/uhci-hcd.c:#include "uhci-debug.c"
./drivers/usb/host/uhci-hcd.c:#include "uhci-q.c"
./drivers/usb/host/uhci-hcd.c:#include "uhci-hub.c"
./fs/compat_binfmt_elf.c:#include "binfmt_elf.c"
./fs/minix/itree_v1.c:#include "itree_common.c"
./fs/minix/itree_v2.c:#include "itree_common.c"
./init/do_mounts_rd.c:#include "../lib/inflate.c"
./init/initramfs.c:#include "../lib/inflate.c"
./kernel/sched.c:#include "sched_idletask.c"
./kernel/sched.c:#include "sched_fair.c"
./kernel/sched.c:#include "sched_rt.c"
./kernel/sched.c:# include "sched_debug.c"
./lib/reed_solomon/reed_solomon.c:#include "encode_rs.c"
./lib/reed_solomon/reed_solomon.c:#include "decode_rs.c"
./lib/reed_solomon/reed_solomon.c:#include "encode_rs.c"
./lib/reed_solomon/reed_solomon.c:#include "decode_rs.c"
./net/netfilter/nf_conntrack_h323_asn1.c:#include "nf_conntrack_h323_types.c"
./sound/core/control.c:#include "control_compat.c"
./sound/core/hwdep.c:#include "hwdep_compat.c"
./sound/core/pcm_native.c:#include "pcm_compat.c"
./sound/core/rawmidi.c:#include "rawmidi_compat.c"
./sound/core/seq/seq_clientmgr.c:#include "seq_compat.c"
./sound/core/timer.c:#include "timer_compat.c"
./sound/isa/cs423x/cs4232.c:#include "cs4236.c"
./sound/isa/gus/interwave-stb.c:#include "interwave.c"
./sound/isa/opti9xx/opti92x-cs4231.c:#include "opti92x-ad1848.c"
./sound/isa/opti9xx/opti93x.c:#include "opti92x-ad1848.c"
./sound/isa/sb/sbawe.c:#include "sb16.c"
./sound/isa/wavefront/wavefront_fx.c:#include "yss225.c"
./sound/oss/msnd_classic.c:#include "msnd_pinnacle.c"
./sound/oss/msnd_classic.h:#  include "msndperm.c"
./sound/oss/msnd_classic.h:#  include "msndinit.c"
./sound/oss/msnd_pinnacle.h:#  include "pndsperm.c"
./sound/oss/msnd_pinnacle.h:#  include "pndspini.c"
./sound/pci/ac97/ac97_codec.c:#include "ac97_patch.c"
./sound/pci/au88x0/au8810.c:#include "au88x0_core.c"
./sound/pci/au88x0/au8810.c:#include "au88x0_pcm.c"
./sound/pci/au88x0/au8810.c:#include "au88x0_mixer.c"
./sound/pci/au88x0/au8810.c:#include "au88x0_mpu401.c"
./sound/pci/au88x0/au8810.c:#include "au88x0_game.c"
./sound/pci/au88x0/au8810.c:#include "au88x0_eq.c"
./sound/pci/au88x0/au8810.c:#include "au88x0_a3d.c"
./sound/pci/au88x0/au8810.c:#include "au88x0_xtalk.c"
./sound/pci/au88x0/au8810.c:#include "au88x0.c"
./sound/pci/au88x0/au8820.c:#include "au88x0_synth.c"
./sound/pci/au88x0/au8820.c:#include "au88x0_core.c"
./sound/pci/au88x0/au8820.c:#include "au88x0_pcm.c"
./sound/pci/au88x0/au8820.c:#include "au88x0_mpu401.c"
./sound/pci/au88x0/au8820.c:#include "au88x0_game.c"
./sound/pci/au88x0/au8820.c:#include "au88x0_mixer.c"
./sound/pci/au88x0/au8820.c:#include "au88x0.c"
./sound/pci/au88x0/au8830.c:#include "au88x0_synth.c"
./sound/pci/au88x0/au8830.c:#include "au88x0_core.c"
./sound/pci/au88x0/au8830.c:#include "au88x0_pcm.c"
./sound/pci/au88x0/au8830.c:#include "au88x0_mixer.c"
./sound/pci/au88x0/au8830.c:#include "au88x0_mpu401.c"
./sound/pci/au88x0/au8830.c:#include "au88x0_game.c"
./sound/pci/au88x0/au8830.c:#include "au88x0_eq.c"
./sound/pci/au88x0/au8830.c:#include "au88x0_a3d.c"
./sound/pci/au88x0/au8830.c:#include "au88x0_xtalk.c"
./sound/pci/au88x0/au8830.c:#include "au88x0.c"
./sound/pci/au88x0/au88x0_a3d.c:#include "au88x0_a3ddata.c"
./sound/pci/au88x0/au88x0_eq.c:#include "au88x0_eqdata.c"
./sound/pci/echoaudio/darla20.c:#include "darla20_dsp.c"
./sound/pci/echoaudio/darla20.c:#include "echoaudio_dsp.c"
./sound/pci/echoaudio/darla20.c:#include "echoaudio.c"
./sound/pci/echoaudio/darla24.c:#include "darla24_dsp.c"
./sound/pci/echoaudio/darla24.c:#include "echoaudio_dsp.c"
./sound/pci/echoaudio/darla24.c:#include "echoaudio.c"
./sound/pci/echoaudio/echo3g.c:#include "echo3g_dsp.c"
./sound/pci/echoaudio/echo3g.c:#include "echoaudio_dsp.c"
./sound/pci/echoaudio/echo3g.c:#include "echoaudio_3g.c"
./sound/pci/echoaudio/echo3g.c:#include "echoaudio.c"
./sound/pci/echoaudio/echo3g.c:#include "midi.c"
./sound/pci/echoaudio/gina20.c:#include "gina20_dsp.c"
./sound/pci/echoaudio/gina20.c:#include "echoaudio_dsp.c"
./sound/pci/echoaudio/gina20.c:#include "echoaudio.c"
./sound/pci/echoaudio/gina24.c:#include "gina24_dsp.c"
./sound/pci/echoaudio/gina24.c:#include "echoaudio_dsp.c"
./sound/pci/echoaudio/gina24.c:#include "echoaudio_gml.c"
./sound/pci/echoaudio/gina24.c:#include "echoaudio.c"
./sound/pci/echoaudio/indigo.c:#include "indigo_dsp.c"
./sound/pci/echoaudio/indigo.c:#include "echoaudio_dsp.c"
./sound/pci/echoaudio/indigo.c:#include "echoaudio.c"
./sound/pci/echoaudio/indigodj.c:#include "indigodj_dsp.c"
./sound/pci/echoaudio/indigodj.c:#include "echoaudio_dsp.c"
./sound/pci/echoaudio/indigodj.c:#include "echoaudio.c"
./sound/pci/echoaudio/indigoio.c:#include "indigoio_dsp.c"
./sound/pci/echoaudio/indigoio.c:#include "echoaudio_dsp.c"
./sound/pci/echoaudio/indigoio.c:#include "echoaudio.c"
./sound/pci/echoaudio/layla20.c:#include "layla20_dsp.c"
./sound/pci/echoaudio/layla20.c:#include "echoaudio_dsp.c"
./sound/pci/echoaudio/layla20.c:#include "echoaudio.c"
./sound/pci/echoaudio/layla20.c:#include "midi.c"
./sound/pci/echoaudio/layla24.c:#include "layla24_dsp.c"
./sound/pci/echoaudio/layla24.c:#include "echoaudio_dsp.c"
./sound/pci/echoaudio/layla24.c:#include "echoaudio_gml.c"
./sound/pci/echoaudio/layla24.c:#include "echoaudio.c"
./sound/pci/echoaudio/layla24.c:#include "midi.c"
./sound/pci/echoaudio/mia.c:#include "mia_dsp.c"
./sound/pci/echoaudio/mia.c:#include "echoaudio_dsp.c"
./sound/pci/echoaudio/mia.c:#include "echoaudio.c"
./sound/pci/echoaudio/mia.c:#include "midi.c"
./sound/pci/echoaudio/mona.c:#include "mona_dsp.c"
./sound/pci/echoaudio/mona.c:#include "echoaudio_dsp.c"
./sound/pci/echoaudio/mona.c:#include "echoaudio_gml.c"
./sound/pci/echoaudio/mona.c:#include "echoaudio.c"
./sound/pci/ens1371.c:#include "ens1370.c"
./sound/pci/nm256/nm256.c:#include "nm256_coef.c"
./sound/usb/usbmixer.c:#include "usbmixer_maps.c"
./sound/usb/usx2y/usx2yhwdeppcm.c:#include "usbusx2yaudio.c"

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

* Re: including .c files ?
  2008-08-08 11:25 including .c files ? Frans Meulenbroeks
@ 2008-08-08 14:30 ` Krzysztof Halasa
  2008-08-08 15:05   ` Chris Friesen
  2008-08-08 15:36 ` Rene Herman
  1 sibling, 1 reply; 6+ messages in thread
From: Krzysztof Halasa @ 2008-08-08 14:30 UTC (permalink / raw)
  To: Frans Meulenbroeks; +Cc: linux-kernel

"Frans Meulenbroeks" <fransmeulenbroeks@gmail.com> writes:

> Generally I would expect that if the .c file contains some standalone
> functionality then it should probably be a .c file on its own with a
> well defined interface.

Doesn't work when you need conditional compilation.
-- 
Krzysztof Halasa

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

* Re: including .c files ?
  2008-08-08 14:30 ` Krzysztof Halasa
@ 2008-08-08 15:05   ` Chris Friesen
  2008-08-08 15:46     ` Krzysztof Halasa
  0 siblings, 1 reply; 6+ messages in thread
From: Chris Friesen @ 2008-08-08 15:05 UTC (permalink / raw)
  To: Krzysztof Halasa; +Cc: Frans Meulenbroeks, linux-kernel

Krzysztof Halasa wrote:
> "Frans Meulenbroeks" <fransmeulenbroeks@gmail.com> writes:
> 
> 
>>Generally I would expect that if the .c file contains some standalone
>>functionality then it should probably be a .c file on its own with a
>>well defined interface.
> 
> 
> Doesn't work when you need conditional compilation.

Sure it does...look at all the kernel Makefiles that compile code based 
on whether a config option is set.

In the case of the scheduler I suspect it's done to break a single 
logical file into several pieces for better readability.

Chris

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

* Re: including .c files ?
  2008-08-08 11:25 including .c files ? Frans Meulenbroeks
  2008-08-08 14:30 ` Krzysztof Halasa
@ 2008-08-08 15:36 ` Rene Herman
  2008-08-08 19:13   ` H. Peter Anvin
  1 sibling, 1 reply; 6+ messages in thread
From: Rene Herman @ 2008-08-08 15:36 UTC (permalink / raw)
  To: Frans Meulenbroeks; +Cc: linux-kernel

On 08-08-08 13:25, Frans Meulenbroeks wrote:

> I was wondering how people feel about including .c files in other .c
> files.
> 
> I saw a few occasions of this. Triggered by that observation I
> decided to do a grep for this (on 2.6.25.7 as that was the one I had
> handy at that moment). Some 268 .c files are included. Seems an awful
> lot for me.
> 
> Do people feel this is good practice? I understand that sometimes it
> is useful (and then you might need to decide on whether to include a
> .c file or to have a .h file with code), but in other places it is
> probably less relevant.
> 
> Generally I would expect that if the .c file contains some standalone
>  functionality then it should probably be a .c file on its own with a
>  well defined interface.
> 
> Curious what others think about this. As attachement I've added the
> output of the grep (slightly edited to remove some false positives,
> like those from the Documentation and scripts directories and those
> who are obviously comments).

As you posted, many of these are in sound/ and many of those #define a 
model and then including the "real source file". Can't say I've been 
very keen on that either and in those cases using a -D commandline 
#define might be better especially since I believe that's actually very 
easy these days.

I also keep a local driver here though that #defines some 50 items and 
then includes the source so that the driver for another version of the 
card can just redefine those and keep the code itself the same (as a 
coincidence, I was just porting that one forward in fact).

This general problem more or less is "library code". Say I have some 
code that I want to use in two different drivers -- I can't just link it 
into both due to symbol clashes if I'd try to then _load_ both drivers. 
So I then have to structure the library code as a completely seperate 
module that both drivers depend on and for small stuff that's sometimes 
just really silly. You still definitely don't want two copies of the 
code to avoid all the usual problems of stuff getting out of sync so a 
solution is to just #include the library code in both after which its 
identifiers can be static.

If you think about it -- in C, #include really at least conceptually 
means "cut & paste this in here, please" meaning headers are not 
anything special and .h and .c seperation is a mere convention.

As we all know, conventions exist _only_ to be violated...

Rene.

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

* Re: including .c files ?
  2008-08-08 15:05   ` Chris Friesen
@ 2008-08-08 15:46     ` Krzysztof Halasa
  0 siblings, 0 replies; 6+ messages in thread
From: Krzysztof Halasa @ 2008-08-08 15:46 UTC (permalink / raw)
  To: Chris Friesen; +Cc: Frans Meulenbroeks, linux-kernel

"Chris Friesen" <cfriesen@nortel.com> writes:

>> Doesn't work when you need conditional compilation.
>
> Sure it does...look at all the kernel Makefiles that compile code
> based on whether a config option is set.

Nope, I meant compilation depending on preprocessor variables defined
(or not) by the including file. CONFIG_* and things like make
variables are completely different things.

Imagine a chip driver (library) doing I/O using either MMIO or
inp/outp. The real card driver uses the library and provides
necessary glue code. You can either a) make I/O real function calls,
call using pointers etc. (slow, should be inline), or b) define the
I/O as inline functions or macros and then #include the library.
-- 
Krzysztof Halasa

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

* Re: including .c files ?
  2008-08-08 15:36 ` Rene Herman
@ 2008-08-08 19:13   ` H. Peter Anvin
  0 siblings, 0 replies; 6+ messages in thread
From: H. Peter Anvin @ 2008-08-08 19:13 UTC (permalink / raw)
  To: Rene Herman; +Cc: Frans Meulenbroeks, linux-kernel

Rene Herman wrote:
> 
> If you think about it -- in C, #include really at least conceptually 
> means "cut & paste this in here, please" meaning headers are not 
> anything special and .h and .c seperation is a mere convention.
> 
> As we all know, conventions exist _only_ to be violated...
> 

The real issue is that the convention -- .c versus .h -- recognize *two* 
kinds of files, but there really are *three* kinds of files:

- Files meant to be included that generate no code (.h)
- Files meant to be included that generate code (???)
- Files not meant to be included (.c)

Some projects -- including the Linux kernel -- have adopted the 
convention that the middle type should be .c, others .h, others probably 
other variants.  You typically want them treated as .h files for 
purposes of generating dependencies, but like .c files for purposes of, 
say, header file include guard checking.

	-hpa

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

end of thread, other threads:[~2008-08-08 19:13 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-08-08 11:25 including .c files ? Frans Meulenbroeks
2008-08-08 14:30 ` Krzysztof Halasa
2008-08-08 15:05   ` Chris Friesen
2008-08-08 15:46     ` Krzysztof Halasa
2008-08-08 15:36 ` Rene Herman
2008-08-08 19:13   ` H. Peter Anvin

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.