|
|
Message-ID: <20180202173501.GS1627@brightrain.aerifal.cx>
Date: Fri, 2 Feb 2018 12:35:01 -0500
From: Rich Felker <dalias@...c.org>
To: musl@...ts.openwall.com
Subject: Re: Why are stdin/stdout/stderr `FILE *const` in musl?
On Fri, Feb 02, 2018 at 02:24:28PM +0100, CodingMarkus wrote:
> Hello everyone!
>
> Just a quick question:
> Why does musl define stdin, stdout, and stderr to be of type `FILE
> *const`? Neither the C standard, nor the POSIX standard require,
They don't require it, but they allow it. musl's implementation _does_
require it, because behind the macros (all the C standard requires to
exist) are const-qualified objects (living inside libc.so/libc.a), and
declaring them with a type that mismatches their definitions would
result in undefined behavior.
> recommend or even imply that it would be allowed that this is a
> `const` pointer. That’s why other C libraries define it as `FILE *`
> only because that matches the examples given by POSIX and that
> matches the description found in any ISO-C standard. Making them
> const only break compatibility with other C libraries, e.g.
> considered this code:
>
> void * getOutputPtr ( void ) {
> if (/* whatever */) {
> return &stdout;
> }
> return &stderr;
> }
>
> This code is correct by C standard and it is correct by POSIX
It's not. As others have noted, stderr is not specified as an object;
it's a macro that expands to an expression with type FILE *. You
cannot take the address of an expression in general.
Rich
Powered by blists - more mailing lists
Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.