You are not logged in.

#1 2021-05-21 22:21:46

Attius_Sullivan
Member
Registered: 2019-11-02
Posts: 47

sys/bsd/tree.h why sometimes include sys/cdefs.h

Hi,

some time ago I stumbled over the `bsd/sys/{tree,queue}.h` C implementations. Now after looking more precise into the source code I read that these headers include `sys/cdefs.h` but when looking around on the internet into some other implementations (`bsd/sys/tree.h` as well) some of those do not include `sys/cdefs.h`.
The actual reason why I'm wondering, is that I see no point in this include, since the `{tree,queue}.h` simply define macros to use queues and trees. From what I know there should be no necessity to include additional headers.

Does someone know why it is that way, or why it might me necessary to include `cdefs.h`? Or since I don't really know where I'd be able to ask questions like this, maybe a tip where to ask as well.

Offline

#2 2021-08-03 16:39:58

lmn
Member
Registered: 2021-05-09
Posts: 33

Re: sys/bsd/tree.h why sometimes include sys/cdefs.h

Going from the version shipped with Arch.

These header files originate from the BSDs. See the top lines in those for more.
BSD and Linux are similar but not the same. One of the things separating them are different implementations of libc.
The BSDs ship with BSD libc, which includes /usr/include/sys/tree.h (missing bsd prefix in include).

Now those versions targeting BSD will usually just use sys/cdefs.h and those targeting linux with libbsd will use bsd/sys/cdefs.h or sys/cdefs.h depending on LIBBSD_OVERLAY.
Some implementations for whatever reason don't use that overlay, the one in Arch does.
See the libbsd man pagefor more.

As to why they are including it in the first place I'm not sure but i think it is for the __unused macro.
This behaves differently on Linux as is does on BSD. Check bsd/sys/cdefs.h on Arch for more.

I know it has been over two months, but if you now can now shed some light on it, I would appreciate it.

Offline

Board footer

Powered by FluxBB