Date: Wed, 5 Mar 2003 16:49:50 -0500 (EST) From: Jonathan Lennox <lennox@cs.columbia.edu> To: FreeBSD-gnats-submit@FreeBSD.org Subject: bin/48958: The type 'bool' has different sizes for C and C++ Message-ID: <200303052149.h25LnoB4080988@conrail.cs.columbia.edu>
next in thread | raw e-mail | index | archive | help
>Number: 48958 >Category: bin >Synopsis: The type 'bool' has different sizes for C and C++ >Confidential: no >Severity: serious >Priority: high >Responsible: freebsd-bugs >State: open >Quarter: >Keywords: >Date-Required: >Class: sw-bug >Submitter-Id: current-users >Arrival-Date: Wed Mar 05 13:50:10 PST 2003 >Closed-Date: >Last-Modified: >Originator: Jonathan Lennox >Release: FreeBSD 4.7-RELEASE i386 >Organization: Columbia University >Environment: System: FreeBSD conrail.cs.columbia.edu 4.7-RELEASE FreeBSD 4.7-RELEASE #2: Sun Nov 10 18:58:39 EST 2002 lennox@conrail.cs.columbia.edu:/usr/obj/usr/src/sys/CONRAIL i386 >Description: The type 'bool' has different sizes and alignment in C and C++ code. In C, the system header file stdbool.h typedef's '_Bool' as 'int', which has size and alignment 4. The type bool is #defined to _Bool. However, in C++, the built-in type 'bool' has size and alignment 1. This means that structures which contain bool values can't be shared between C and C++ code. >How-To-Repeat: Compile and execute the following program as C and C++ code, with /usr/bin/cc and /usr/bin/c++. #include <stdio.h> #ifndef __cplusplus #include <stdbool.h> #endif int main() { printf("%d\n", sizeof(bool)); return 0; } >Fix: The correct fix would be to change /usr/include/stdbool.h to say 'typedef char _Bool' rather than 'typedef int _Bool'. This changes the C ABI for FreeBSD 4.x, but it makes it agree with the C++ ABI, and the C ABI for FreeBSD 5.x. Workarounds: * Use FreeBSD 5.x (presumably; not tested). * Don't use <stdbool.h>; instead, use a local typedef of bool as char. >Release-Note: >Audit-Trail: >Unformatted: To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-bugs" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200303052149.h25LnoB4080988>