docs: Mention platform-specific predefined macros

The platform-specific predefined macros provided by various compilers
sometimes capture subtle differences of meaning, like the distinction
between the Linux kernel and a glibc-based (GNU/Linux) user-space.
It would be difficult to capture those subtleties in GLib-specific
convenience macros, particularly for platforms that we don't use
ourselves.

Instead, recommend that anyone who is already writing platform-specific
code should use the platform-specific predefined macros directly.

Alternative to !2986.

Signed-off-by: Simon McVittie <smcv@collabora.com>
This commit is contained in:
Simon McVittie 2022-10-21 13:41:06 +01:00 committed by Philip Withnall
parent 02db6107ce
commit 871237b9d5

View File

@ -2020,6 +2020,22 @@
*
* This macro is defined only on UNIX. So you can bracket
* UNIX-specific code in "\#ifdef G_OS_UNIX".
*
* To detect whether to compile features that require a specific kernel
* or operating system, check for the appropriate OS-specific predefined
* macros instead, for example:
*
* - Linux kernel (any libc, including glibc, musl or Android): `\#ifdef __linux__`
* - Linux kernel and GNU user-space: `\#if defined(__linux__) && defined(__GLIBC__)`
* - FreeBSD kernel (any libc, including glibc): `\#ifdef __FreeBSD_kernel__`
* - FreeBSD kernel and user-space: `\#ifdef __FreeBSD__`
*
* See <https://sourceforge.net/p/predef/wiki/OperatingSystems/> for more.
*
* GLib defines OS-detection macros for some categories of systems
* that can be less straightforward to detect, such as %G_OS_DARWIN, but
* intentionally does not provide its own equivalents of macros like
* `__linux__`.
*/
/**