Re: bool and C23

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Monday I wrote:
> > to exclude other problems, we need to check it on a platform-by-platform
> > basis.

This is the situation on the various platforms:

  * In C++ mode,
    - either the C <stdbool.h> is used,
    - or a C++ <stdbool.h> exists that
        #include <cstdbool>
    - or a C++ <stdbool.h> exists that #include <__config>,
      and the latter does:
        Linux: #include <features.h>
        FreeBSD: #include <sys/endian.h>, #include <osreldate.h>
        NetBSD: #include <sys/endian.h>
        Windows store apps: #include <winapifamily.h>
        Solaris: #include <sys/isa_defs.h>
        else: #include <endian.h>

    The latter includes various OS stuff, and should therefore be
    avoided when possible. Since a compilation unit cannot be ISO C 23
    and C++ at the same time, it is easy to achieve: Wrap the new
    config.h additions in
      #ifndef __cplusplus
      ...
      #endif

  * In C mode: <stdbool.h> does

    AIX: #include <standards.h>, defines only macros
    FreeBSD: self-contained
    Haiku: self-contained
    HP-UX: #include <sys/stdsyms.h>, defines only macros
    macOS: self-contained
    mingw: self-contained
    Minix: self-contained
    musl: self-contained
    NetBSD: self-contained
    OpenBSD: self-contained
    Solaris 10: #include <sys/feature_tests.h> -> #include <sys/ccompile.h>, #include <sys/isa_defs.h>, defines only macros
    Solaris 11: #include <sys/feature_tests.h>

    So, in this case, it is OK to #include <stdbool.h>, since it
    does not include header files with function declarations, only
    header files with macro definitions.

Paul Eggert wrote:
> In the long run this problem will vanish, as in the long run config.h 
> will do nothing (that's all that's needed for C23 and C++).

I agree.

> In the shorter run I think we'll be OK for C17 and earlier if we include 
> <stdbool.h> on platforms where bool+true+false don't work out of the 
> box, because (unlike some other .h files) stdbool.h doesn't tend to 
> cause conflicts.

Yes. Based on the analysis above, this should work.

So, IIUC, what we should do, is:

  - Determine GL_GENERATE_STDBOOL_H as in gnulib/m4/stdbool.m4,
  - If it is true, add to <config.h> the lines

      #ifndef __cplusplus
      ... current contents of gnulib/m4/stdbool.in.h ...
      #endif

  - Otherwise, test "$ac_cv_header_stdbool_h".
  - If it is != 'yes', add to <config.h> the lines

      #ifndef __cplusplus
      #include <stdbool.h>
      #endif

Bruno







[Index of Archives]     [GCC Help]     [Kernel Discussion]     [RPM Discussion]     [Red Hat Development]     [Yosemite News]     [Linux USB]     [Samba]

  Powered by Linux