Date: Thu, 10 Mar 2011 09:17:28 -0800 From: mdf@FreeBSD.org To: FreeBSD Arch <freebsd-arch@freebsd.org> Subject: style(9) rules for nested includes Message-ID: <AANLkTikqBJON46-EJFPPktT82L8dgX6dwwDrxWwFqumU@mail.gmail.com>
next in thread | raw e-mail | index | archive | help
I recall a recent discussion/PR about nested includes in the context of <sys/linker_set.h> and <sys/queue.h> being a few of the only ones allowed. However, I don't see anything in style(9) about this. One rule for nested includes I've heard (that FreeBSD doesn't use, but just mentioning it for variety) is that every header file should compile on its own; that is, a .c file with nothing but #include <header.h> should compile without errors. This rule also makes some sense with the FreeBSD style convention of alphabetizing includes; otherwise it's kinda just happenstance that e.g. <sys/lock.h> comes alphabetically before <sys/sx.h>, <sys/mutex.h>, <sys/rwlock.h> and <sys/rmlock.h>, and barely before <sys/lockmgr.h>. Now we come to the reason I ask. I'm working on a patch to change the static sysctl code to use the standard SYSININT/SYSUNINIT code rather than have special treatment in kern_linker.c, but to do this I need to either change quite a few places that include <sys/sysctl.h>, or include <sys/kernel.h> instead of <sys/linker_set.h> in sysctl.h, as the SI_SUB_SYSCTLS value isn't visible otherwise. This, though, shows a bug in <sys/kernel.h>, where it uses the constant MAXPATHLEN in the extern declaration of kernelname[] (which itself I think is not standard C, IIRC, but there are several uses of sizeof(kernelname) that don't work otherwise). So then <sys/kernel.h> needs <sys/param.h> to build. So, which files are okay to include in an include file? Does someone (I'll do it if we can agree on a list) want to put this in style(9)? Thanks, matthew
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?AANLkTikqBJON46-EJFPPktT82L8dgX6dwwDrxWwFqumU>