From owner-freebsd-bugs Wed Mar 5 13:50:16 2003 Delivered-To: freebsd-bugs@hub.freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 8FB1F37B405 for ; Wed, 5 Mar 2003 13:50:13 -0800 (PST) Received: from freefall.freebsd.org (freefall.freebsd.org [216.136.204.21]) by mx1.FreeBSD.org (Postfix) with ESMTP id C257843F75 for ; Wed, 5 Mar 2003 13:50:10 -0800 (PST) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (gnats@localhost [127.0.0.1]) by freefall.freebsd.org (8.12.6/8.12.6) with ESMTP id h25LoANS075085 for ; Wed, 5 Mar 2003 13:50:10 -0800 (PST) (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.12.6/8.12.6/Submit) id h25LoARg075084; Wed, 5 Mar 2003 13:50:10 -0800 (PST) Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id C18AA37B401 for ; Wed, 5 Mar 2003 13:49:54 -0800 (PST) Received: from cs.columbia.edu (cs.columbia.edu [128.59.16.20]) by mx1.FreeBSD.org (Postfix) with ESMTP id 8E79F43FDD for ; Wed, 5 Mar 2003 13:49:53 -0800 (PST) (envelope-from lennox@cs.columbia.edu) Received: from conrail.cs.columbia.edu (conrail.cs.columbia.edu [128.59.19.147]) by cs.columbia.edu (8.12.8/8.12.6) with ESMTP id h25LnqBS023509 (version=TLSv1/SSLv3 cipher=EDH-RSA-DES-CBC3-SHA bits=168 verify=NOT) for ; Wed, 5 Mar 2003 16:49:52 -0500 (EST) Received: from conrail.cs.columbia.edu (localhost [127.0.0.1]) by conrail.cs.columbia.edu (8.12.6/8.12.6) with ESMTP id h25LnpQS080989 for ; Wed, 5 Mar 2003 16:49:51 -0500 (EST) (envelope-from lennox@conrail.cs.columbia.edu) Received: (from lennox@localhost) by conrail.cs.columbia.edu (8.12.6/8.12.6/Submit) id h25LnoB4080988; Wed, 5 Mar 2003 16:49:50 -0500 (EST) Message-Id: <200303052149.h25LnoB4080988@conrail.cs.columbia.edu> Date: Wed, 5 Mar 2003 16:49:50 -0500 (EST) From: Jonathan Lennox Reply-To: Jonathan Lennox To: FreeBSD-gnats-submit@FreeBSD.org X-Send-Pr-Version: 3.113 Subject: bin/48958: The type 'bool' has different sizes for C and C++ Sender: owner-freebsd-bugs@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.org >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 #ifndef __cplusplus #include #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 ; 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