On 23/09/28 09:02AM, David Demelier wrote:
> Not sure if that helps but I eventually stopped adding flags at all and
> use just the defaults everywhere. Otherwise I'd be glad to understand
> if there is a complete and strict conformance explanation on those
> combinations.
As Adam noted, the macros need to be defined before including the headers. More
details can be found in feature_test_macros(7)[1] and libc documentation.
musl libc documentation[2] states (search for "Feature Test Macros Supported by
musl")
> If no feature test macros are defined, musl's headers operate in
> "default features" mode, exposing the equivalent of the `_BSD_SOURCE`
> option below. This corresponds fairly well to what most applications
> unaware of feature test macros expect, and also provides a number of
> more modern features.
>
> Otherwise, if at least one of the below-listed feature test macros is
> defined, they are treated additively, starting from pure ISO C as a
> base. Unless otherwise specified, musl ignores the value of the macro
> and only checks whether it is defined.
Likewise, glibc documentation[3] on feature test macros states:
> Be aware that compiler options also affect included features:
>
> * If you use a strict conformance option, features beyond those from the
> compiler’s language version will be disabled, though feature test macros
> may be used to enable them.
> * Features enabled by compiler options are not overridden by feature test
> macros.
It is worth noting that most suckless programs don't define feature test macros
inside of the source code. Instead, they are usually specified in config.mk as
command line arguments passed to the compiler (thus guaranteed to not suffer
from header inclusion before defining feature test macros). This also gives a
clue on how to use termbox2.h properly.
Also:
https://suckless.org/coding_style/
> C Features
>
> * Use C99 without extensions (ISO/IEC 9899:1999).
> * Use POSIX.1-2008:
> - When using gcc define _POSIX_C_SOURCE 200809L.
> - Alternatively define _XOPEN_SOURCE 700.
[1]:
https://linux.die.net/man/7/feature_test_macros
[2]:
https://musl.libc.org/doc/1.1.24/manual.html
[3]:
https://www.gnu.org/software/libc/manual/html_node/Feature-Test-Macros.html#index-_005fDEFAULT_005fSOURCE
Received on Thu Sep 28 2023 - 13:34:43 CEST