From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/12444 Path: news.gmane.org!.POSTED!not-for-mail From: CodingMarkus Newsgroups: gmane.linux.lib.musl.general Subject: Why are stdin/stdout/stderr `FILE *const` in musl? Date: Fri, 2 Feb 2018 14:24:28 +0100 Message-ID: <1E109BA9-57C0-42DB-9B43-8ADE27F9E76C@hanauska.name> Reply-To: musl@lists.openwall.com NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 (Mac OS X Mail 11.2 \(3445.5.20\)) Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Trace: blaine.gmane.org 1517577789 28193 195.159.176.226 (2 Feb 2018 13:23:09 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Fri, 2 Feb 2018 13:23:09 +0000 (UTC) To: musl@lists.openwall.com Original-X-From: musl-return-12460-gllmg-musl=m.gmane.org@lists.openwall.com Fri Feb 02 14:23:05 2018 Return-path: Envelope-to: gllmg-musl@m.gmane.org Original-Received: from mother.openwall.net ([195.42.179.200]) by blaine.gmane.org with smtp (Exim 4.84_2) (envelope-from ) id 1ehbIe-0005iZ-BE for gllmg-musl@m.gmane.org; Fri, 02 Feb 2018 14:22:40 +0100 Original-Received: (qmail 24563 invoked by uid 550); 2 Feb 2018 13:24:41 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-ID: Original-Received: (qmail 24523 invoked from network); 2 Feb 2018 13:24:40 -0000 X-Virus-Scanned: amavisd-new at heinlein-support.de Xref: news.gmane.org gmane.linux.lib.musl.general:12444 Archived-At: 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=E2=80=99s 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=E2=80=99t 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.=20 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=E2=80=99t = have to expect a const here and thus this code would usually not require = a cast. I don=E2=80=99t know what the intention is behind making stdX = const, it=E2=80=99s 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