Commit 4317110
committed
docs: Modify include ordering paragraph to order linux headers last
All linux headers include "libc-compat.h" which checks whether various
glibc headers have already been included and if that's the case, sets
various defines which instruct the other linux headers to skip defining
various definitions themselves to avoid conflicts.
Unfortunately, various glibc headers are missing similar checks, most
notable <netinet/in.h> and <net/if.h>. This means that if the linux headers
are included before the glibc ones, including the glibc ones will cause
compilation errors due to redefining structs.
Note that including the relevant glibc header before the corresponding
linux header (e.g. <netinet/in.h> before <linux/in.h> is not sufficient,
as all linux headers include libc-compat.h and libc-compat.h checks once
(the first time it's included) which relevant glibc headers have been
included by that point and sets in stone what the other linux headers will
do when included. So if <linux/if_arp.h> is included first, followed by
<netinet/in.h> followed by <linux/in.h>, parsing <linux/in.h> will still
fail because <linux/if_arp.h> will include <linux/libc-compat.h>, which
will check if <netinet/in.h> has already bee included, which isn't the
case, and so it will instruct <linux/in.h> to define all its structs, which
will cause redefinitions errors because <netinet/in.h> will also include all
its structs.
Even if glibc fixes its <netinet/in.h> header to not define structs that
have already been defined by <linux/in.h>, the above scenario would still fail,
as <linux/libc-compat.h> would still tell <linux/in.h> to define all its structs,
and <netinet/in.h> would also still define all its structs as <linux/in.h> hasn't
been included yet by the time <netinet/in.h> is included.1 parent cf0f741 commit 4317110
1 file changed
+11
-9
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
344 | 344 | | |
345 | 345 | | |
346 | 346 | | |
347 | | - | |
348 | | - | |
349 | | - | |
350 | | - | |
351 | | - | |
352 | | - | |
353 | | - | |
354 | | - | |
355 | | - | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
356 | 358 | | |
357 | 359 | | |
358 | 360 | | |
| |||
0 commit comments