From lennox@cs.columbia.edu  Wed Mar  5 13:49:54 2003
Return-Path: <lennox@cs.columbia.edu>
Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125])
	by hub.freebsd.org (Postfix) with ESMTP id C18AA37B401
	for <FreeBSD-gnats-submit@freebsd.org>; 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 <FreeBSD-gnats-submit@freebsd.org>; 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 <FreeBSD-gnats-submit@freebsd.org>; 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 <FreeBSD-gnats-submit@freebsd.org>; 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 <lennox@cs.columbia.edu>
Reply-To: Jonathan Lennox <lennox@cs.columbia.edu>
To: FreeBSD-gnats-submit@freebsd.org
Cc:
Subject: The type 'bool' has different sizes for C and C++
X-Send-Pr-Version: 3.113
X-GNATS-Notify:

>Number:         48958
>Category:       bin
>Synopsis:       The type 'bool' has different sizes for C and C++
>Confidential:   no
>Severity:       serious
>Priority:       high
>Responsible:    freebsd-standards
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Wed Mar 05 13:50:10 PST 2003
>Closed-Date:    Tue Aug 24 03:49:24 GMT 2004
>Last-Modified:  Tue Aug 24 03:49:24 GMT 2004
>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:
Responsible-Changed-From-To: freebsd-bugs->freebsd-standards 
Responsible-Changed-By: roam 
Responsible-Changed-When: Thu Mar 6 06:23:01 PST 2003 
Responsible-Changed-Why:  
Over to the -standards list to take a look at this one. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=48958 
State-Changed-From-To: open->closed 
State-Changed-By: tjr 
State-Changed-When: Tue Aug 24 03:46:30 GMT 2004 
State-Changed-Why:  
This problem does not exist in -current. It is not possible to fix in 
-stable without breaking certain binary interfaces. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=48958 
>Unformatted:
