mailing list of musl libc
 help / color / mirror / code / Atom feed
From: Jens Gustedt <jens.gustedt@inria.fr>
Cc: musl@lists.openwall.com
Subject: Re: stdbool.h does not define _Bool when included by C++ code
Date: Tue, 1 Aug 2017 09:24:07 +0200	[thread overview]
Message-ID: <20170801092407.12885f12@inria.fr> (raw)
In-Reply-To: <20170801013122.GC1627@brightrain.aerifal.cx>

[-- Attachment #1: Type: text/plain, Size: 2704 bytes --]

Hello,

On Mon, 31 Jul 2017 21:31:22 -0400 Rich Felker <dalias@libc.org> wrote:

> On Tue, Aug 01, 2017 at 09:06:01AM +1200, Michael Clark wrote:
> >   
> > > On 31 Jul 2017, at 9:46 PM, Jens Gustedt <jens.gustedt@inria.fr>
> > > wrote:
> > > 
> > > Hello,
> > > 
> > > On Mon, 31 Jul 2017 11:18:28 +0200 Szabolcs Nagy <nsz@port70.net>
> > > wrote: 
>  [...]  
> > > 
> > > 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.  
> > 
> > It’s 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
> >   
> > > I think that applications that want to be shure that their code
> > > compiles for both should use "bool" and should do
> > > 
> > > #ifndef __cplusplus
> > > # include <stdbool.h>
> > > #endif  
> > 
> > I think you’re 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.  
> 
> 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

-- 
:: 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 ::

[-- Attachment #2: Digitale Signatur von OpenPGP --]
[-- Type: application/pgp-signature, Size: 195 bytes --]

      reply	other threads:[~2017-08-01  7:24 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-07-28 10:21 Michael Clark
2017-07-28 13:01 ` Rich Felker
2017-07-31  9:18 ` Szabolcs Nagy
2017-07-31  9:46   ` Jens Gustedt
2017-07-31 21:06     ` Michael Clark
2017-08-01  1:31       ` Rich Felker
2017-08-01  7:24         ` Jens Gustedt [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20170801092407.12885f12@inria.fr \
    --to=jens.gustedt@inria.fr \
    --cc=musl@lists.openwall.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/musl/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).