Re: [dev] [edit] Introducing edit, a simple text editor

From: Страхиња Радић <>
Date: Wed, 27 Sep 2023 22:33:24 +0200

On closer inspection, termbox2.h does include signal.h itself[1], and
additionally defines _XOPEN_SOURCE[2] and _DEFAULT_SOURCE, so the inclusion of
signal.h can't be escaped.

My testing has shown that when -std=c99 is specified, it is as if that switch
explicitly undefines _DEFAULT_SOURCE/_XOPEN_SOURCE **defined inside the header
file** (this is the weird part). If -D_DEFAULT_SOURCE is given as an argument,
or without -std=c99, when gcc is called directly rather than through the
wrapper, c99, there are no warnings:

        $ c99 -E edit.c | grep fileno
            if (fstat(fileno(fp), &st) != 0) {
        $ gcc -E edit.c | grep fileno
        int fileno(FILE *);
        int fileno_unlocked(FILE *);
            if (fstat(fileno(fp), &st) != 0) {
        $ c99 -D_DEFAULT_SOURCE -E edit.c | grep fileno
        int fileno(FILE *);
        int fileno_unlocked(FILE *);
            if (fstat(fileno(fp), &st) != 0) {

I use Alpine Linux, thus musl libc. Searching the web yielded the answer[3] on
Stack Overflow, though:

> If you want this to cleanly compile with -std=c99, you must consider the
> inclusion of the _DEFAULT_SOURCE feature test macro

I'm not sure about why you wouldn't want POSIX compliance though (To compile on
Plan9? But it has APE[4]).


Received on Wed Sep 27 2023 - 22:33:24 CEST

This archive was generated by hypermail 2.3.0 : Wed Sep 27 2023 - 22:36:08 CEST