[racket-dev] ffi sizeof bool

From: Matthew Flatt (mflatt at cs.utah.edu)
Date: Fri Apr 4 12:22:36 EDT 2014

The current `_bool` is pre-standard. It specifically reflects (I think)
the absence of a bool type in libffi, which in turn is an artifact (I
assume) of `bool` not existing in a C standard before C99.

Lots of libraries have a "bool" variant that is `int`-sized, so I
imagine that's where the definition of `_bool` came from. For example,
boolean fields in public libjpeg structures are `int`-sized as the
library is usually built (except on Windows). Similarly, a `gboolean`
in GLib is an alias for `gint`, which is an alias for `int`.

At Fri, 4 Apr 2014 18:08:45 +0200, Tobias Hammer wrote:
> Just checked and _Bool is also 1 byte, same as C++. What i don't  
> understand yet is to which standard does the current _bool conform? I  
> couldn't find any platform with int sized bool.
> 
> 
> On Fri, 04 Apr 2014 17:10:30 +0200, Matthew Flatt <mflatt at cs.utah.edu>  
> wrote:
> 
> > Yes, `_bool` is a problem. I'll add a `_stdbool` that corresponds to
> > `bool` from C99's <stdbool.h>, which I imagine must be the same as
> > `bool` in C++.
> >
> > At Fri, 4 Apr 2014 08:56:18 +0200, Tobias Hammer wrote:
> >> Hi,
> >>
> >> i guess this shouldn't happen:
> >>
> >> $ cat s.cc
> >> #include <stdio.h>
> >> int main()
> >> {
> >>      printf("%zu\n", sizeof(bool));
> >> }
> >> $ g++ s.cc -o s
> >> $ ./s
> >> 1
> >>
> >> Welcome to Racket v6.0.0.5.
> >> -> (require ffi/unsafe)
> >> -> (ctype-sizeof _bool)
> >> 4
> >>
> >> Tested with multiple unix/linux OS, all gcc > 4.3.4
> >>
> >> Tobias
> >> _________________________
> >>   Racket Developers list:
> >>   http://lists.racket-lang.org/dev
> 
> 
> -- 
> Tobias Hammer
> DLR / Robotics and Mechatronics Center (RMC)
> Muenchner Str. 20, D-82234 Wessling
> Tel.: 08153/28-1487
> Mail: tobias.hammer at dlr.de

Posted on the dev mailing list.