Message ID | 1479241752-29927-1-git-send-email-stefanha@redhat.com |
---|---|
State | New |
Headers | show |
On 11/15/2016 02:29 PM, Stefan Hajnoczi wrote: > It was not obvious to me why "qemu/osdep.h" must be the first #include. > This documents the rationale and the overall #include order. > > Cc: Fam Zheng <famz@redhat.com> > Cc: Markus Armbruster <armbru@redhat.com> > Cc: Eric Blake <eblake@redhat.com> > Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> > --- > HACKING | 15 +++++++++++++++ > 1 file changed, 15 insertions(+) > > +1.2. Include directives > + > +Order include directives as follows: > + > +#include "qemu/osdep.h" /* Always first... */ > +#include <...> /* then system headers... */ > +#include "..." /* and finally QEMU headers. */ > + > +The "qemu/osdep.h" header contains preprocessor macros that affect the behavior > +of core system headers like <stdint.h>. It must be the first include so that > +core system headers included by external libraries get the preprocessor macros > +that QEMU depends on. Might be worth mentioning that only .c files include osdep.h (.h files do not need to, because they can only be included by a .c file that has already included osdep.h first).
Eric Blake <eblake@redhat.com> writes: > On 11/15/2016 02:29 PM, Stefan Hajnoczi wrote: >> It was not obvious to me why "qemu/osdep.h" must be the first #include. >> This documents the rationale and the overall #include order. >> >> Cc: Fam Zheng <famz@redhat.com> >> Cc: Markus Armbruster <armbru@redhat.com> >> Cc: Eric Blake <eblake@redhat.com> >> Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> >> --- >> HACKING | 15 +++++++++++++++ >> 1 file changed, 15 insertions(+) >> > >> +1.2. Include directives >> + >> +Order include directives as follows: >> + >> +#include "qemu/osdep.h" /* Always first... */ >> +#include <...> /* then system headers... */ >> +#include "..." /* and finally QEMU headers. */ >> + >> +The "qemu/osdep.h" header contains preprocessor macros that affect the behavior >> +of core system headers like <stdint.h>. It must be the first include so that >> +core system headers included by external libraries get the preprocessor macros >> +that QEMU depends on. > > Might be worth mentioning that only .c files include osdep.h (.h files > do not need to, because they can only be included by a .c file that has > already included osdep.h first). Yes, please, but make it "headers should not include osdep.h".
On Wed, Nov 16, 2016 at 9:39 AM, Markus Armbruster <armbru@redhat.com> wrote: > Eric Blake <eblake@redhat.com> writes: > >> On 11/15/2016 02:29 PM, Stefan Hajnoczi wrote: >>> It was not obvious to me why "qemu/osdep.h" must be the first #include. >>> This documents the rationale and the overall #include order. >>> >>> Cc: Fam Zheng <famz@redhat.com> >>> Cc: Markus Armbruster <armbru@redhat.com> >>> Cc: Eric Blake <eblake@redhat.com> >>> Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> >>> --- >>> HACKING | 15 +++++++++++++++ >>> 1 file changed, 15 insertions(+) >>> >> >>> +1.2. Include directives >>> + >>> +Order include directives as follows: >>> + >>> +#include "qemu/osdep.h" /* Always first... */ >>> +#include <...> /* then system headers... */ >>> +#include "..." /* and finally QEMU headers. */ >>> + >>> +The "qemu/osdep.h" header contains preprocessor macros that affect the behavior >>> +of core system headers like <stdint.h>. It must be the first include so that >>> +core system headers included by external libraries get the preprocessor macros >>> +that QEMU depends on. >> >> Might be worth mentioning that only .c files include osdep.h (.h files >> do not need to, because they can only be included by a .c file that has >> already included osdep.h first). > > Yes, please, but make it "headers should not include osdep.h". Will send v2. Stefan
diff --git a/HACKING b/HACKING index 20a9101..ced1236 100644 --- a/HACKING +++ b/HACKING @@ -1,10 +1,25 @@ 1. Preprocessor +1.1. Variadic macros + For variadic macros, stick with this C99-like syntax: #define DPRINTF(fmt, ...) \ do { printf("IRQ: " fmt, ## __VA_ARGS__); } while (0) +1.2. Include directives + +Order include directives as follows: + +#include "qemu/osdep.h" /* Always first... */ +#include <...> /* then system headers... */ +#include "..." /* and finally QEMU headers. */ + +The "qemu/osdep.h" header contains preprocessor macros that affect the behavior +of core system headers like <stdint.h>. It must be the first include so that +core system headers included by external libraries get the preprocessor macros +that QEMU depends on. + 2. C types It should be common sense to use the right type, but we have collected
It was not obvious to me why "qemu/osdep.h" must be the first #include. This documents the rationale and the overall #include order. Cc: Fam Zheng <famz@redhat.com> Cc: Markus Armbruster <armbru@redhat.com> Cc: Eric Blake <eblake@redhat.com> Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> --- HACKING | 15 +++++++++++++++ 1 file changed, 15 insertions(+)