|
|
Message-Id: <1E109BA9-57C0-42DB-9B43-8ADE27F9E76C@hanauska.name>
Date: Fri, 2 Feb 2018 14:24:28 +0100
From: CodingMarkus <CodingMarkus@...auska.name>
To: musl@...ts.openwall.com
Subject: Why are stdin/stdout/stderr `FILE *const` in musl?
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, 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 standard but it won’t compile with strict compiler settings when using musl as the compiler complains that the `const` is lost and there is no explicitly cast for that.
error: cannot initialize return object of type 'void *' with an rvalue of type 'FILE *const *'
The reason why there is no cast is because a C programmer doesn’t have to expect a const here and thus this code would usually not require a cast. I don’t know what the intention is behind making stdX const, it’s probably a good one, but if that makes your header files incompatible to both, C and POSIX standard, then it is a horrible change that only means trouble and will not improve anything for anyone.
Regards,
Markus
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.