From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/11770 Path: news.gmane.org!.POSTED!not-for-mail From: Jens Gustedt Newsgroups: gmane.linux.lib.musl.general Subject: Re: stdbool.h does not define _Bool when included by C++ code Date: Tue, 1 Aug 2017 09:24:07 +0200 Organization: inria.fr Message-ID: <20170801092407.12885f12@inria.fr> References: <20170731091828.GA15263@port70.net> <20170731114623.0a449442@inria.fr> <53FF0182-D2D6-4D9D-9E99-5C9848A2A184@mac.com> <20170801013122.GC1627@brightrain.aerifal.cx> Reply-To: musl@lists.openwall.com NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; boundary="Sig_/xeSrn1gVijKHA1xkHjEL=Ua"; protocol="application/pgp-signature" X-Trace: blaine.gmane.org 1501572263 21638 195.159.176.226 (1 Aug 2017 07:24:23 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Tue, 1 Aug 2017 07:24:23 +0000 (UTC) Cc: musl@lists.openwall.com Original-X-From: musl-return-11783-gllmg-musl=m.gmane.org@lists.openwall.com Tue Aug 01 09:24:19 2017 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 1dcRXO-0005Kv-H1 for gllmg-musl@m.gmane.org; Tue, 01 Aug 2017 09:24:18 +0200 Original-Received: (qmail 11462 invoked by uid 550); 1 Aug 2017 07:24:21 -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 11444 invoked from network); 1 Aug 2017 07:24:21 -0000 X-IronPort-AV: E=Sophos;i="5.41,305,1498514400"; d="scan'208";a="285659315" In-Reply-To: <20170801013122.GC1627@brightrain.aerifal.cx> X-Mailer: Claws Mail 3.14.1 (GTK+ 2.24.31; x86_64-pc-linux-gnu) X-Face: iVBORw0KGgoAAAANSUhEUgAAADAAAAAwBAMAAAClLOS0AAAAAXNSR0IArs4c6QAAACRQTFRFERslNjAsLTE9Ok9wUk9TaUs8iWhSrYZkj42Rz6aD3sGZ Xref: news.gmane.org gmane.linux.lib.musl.general:11770 Archived-At: --Sig_/xeSrn1gVijKHA1xkHjEL=Ua Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Hello, On Mon, 31 Jul 2017 21:31:22 -0400 Rich Felker wrote: > On Tue, Aug 01, 2017 at 09:06:01AM +1200, Michael Clark wrote: > > =20 > > > On 31 Jul 2017, at 9:46 PM, Jens Gustedt > > > wrote: > > >=20 > > > Hello, > > >=20 > > > On Mon, 31 Jul 2017 11:18:28 +0200 Szabolcs Nagy > > > wrote:=20 > [...] =20 > > >=20 > > > Basically stdbool.h is already a header to accomodate C++ usage of > > > bool, false and true to C. I makes not much sense to include this > > > in C++ code. =20 > >=20 > > It=E2=80=99s useful exactly for the case where you have C code in your = C++, > > which is why I suspect GCC has the condition in its version of > > stdbool.h > > =20 > > > I think that applications that want to be shure that their code > > > compiles for both should use "bool" and should do > > >=20 > > > #ifndef __cplusplus > > > # include > > > #endif =20 > >=20 > > I think you=E2=80=99re missing the point. C code can use _Bool and this= can > > be put through the C++ front-end. Compiler explorer does this by > > default, and the GCC and glibc headers already have the fix, which > > is #define _Bool bool (in the patch) for the case where C code is > > fed in to the C++ front end. =20 >=20 > Compiling C code with a C++ compiler is utterly wrong, and will fail > in more subtle ways; erroring out early seems much more desirable. C > is not a subset of C++, and even the syntax that's in the intersection > of both languages is semantically different between them. I agree, and I should have been more precise for the use case where this actually makes sense. The only compatibility between C an C++ that is ensured is ABI compatibility. And here what I said above is a reasonable way to write *header* files that can be included by both languages. So such a header is *not* simply "C code that is compiled as C++". There are several syntax problems for such headers, simple ones as _Bool, but also _Noreturn, _Static_assert, and more difficult ones as _Atomic or enumeration types ... Such a header has to be carefully designed to fit to both languages. Placing __cplusplus ifdef's into some of the headers could be a strategy to ease the pain. Defining _Bool and stuff in some way for C++ would just be pushing things under the carpet and hide difficulties that reduce awareness of the problem. Jens --=20 :: INRIA Nancy Grand Est ::: Camus ::::::: ICube/ICPS ::: :: ::::::::::::::: office Strasbourg : +33 368854536 :: :: :::::::::::::::::::::: gsm France : +33 651400183 :: :: ::::::::::::::: gsm international : +49 15737185122 :: :: http://icube-icps.unistra.fr/index.php/Jens_Gustedt :: --Sig_/xeSrn1gVijKHA1xkHjEL=Ua Content-Type: application/pgp-signature Content-Description: Digitale Signatur von OpenPGP -----BEGIN PGP SIGNATURE----- iF0EARECAB0WIQSN9stI2OFN1pLljN0P0+hp2tU34gUCWYAslwAKCRAP0+hp2tU3 4v5hAJ0WLlOCNfkMNmCoQsysrXjBOMuwcgCgjY4DDkrX7dfpGK6AkIkdkXa2+Uk= =fQiX -----END PGP SIGNATURE----- --Sig_/xeSrn1gVijKHA1xkHjEL=Ua--