public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
* sizeof (_Bool)
@ 2002-04-26 15:52 Stan Shebs
  2002-04-26 16:29 ` Joseph S. Myers
                   ` (2 more replies)
  0 siblings, 3 replies; 11+ messages in thread
From: Stan Shebs @ 2002-04-26 15:52 UTC (permalink / raw)
  To: gcc

When Joseph Myers added _Bool as part of his C99 work
(see http://gcc.gnu.org/ml/gcc-patches/2000-10/msg01127.html), he
chose to give it the same size as chars, even though this made
it binary incompatible with the previous typedef of "bool" as
int in stdbool.h.

Well, it bit somebody here using almost-3.1 to compile part of
Mac OS X.  We've been using stdbool.h for some time to provide a
basic definition of bool, and there is lots of API that makes
reference to bool, for instance in fields of structs.  Now it
happens that these APIs are generally internal, but of course
we expect to deliver apps such as iPhoto that will work on 10.1
(which is built with 2.95.2 and thus has 4-byte bools) and later
OSes built with 3.1, plus we don't know how many third parties
have already delivered libraries with 4-byte bools wired into
their interfaces.

Since there are now millions of machines out in the field with
OS X on them, you can imagine that we're pretty worried about
binary compatibility - we don't want Grandma's family pictures
trashed by a newly-downloaded iPhoto!

So we're proposing to make _Bool's size target-specific, and
to add a macro something like BOOL_TYPE_SIZE that can default
to CHAR_TYPE_SIZE, and that Darwin configs can set to 32.  I'd
appreciate any comments or feedback on the idea, including
possible gotchas relating to C++ bool.

Also, if anybody knows of any *other* C ABI changes between 2.95
and 3.1, I'd sure like to hear about them.  Presumably there aren't
many, since we've been building mixed systems for months and haven't
really been hosed before now.  Thanks!

Stan

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: sizeof (_Bool)
  2002-04-26 15:52 sizeof (_Bool) Stan Shebs
@ 2002-04-26 16:29 ` Joseph S. Myers
  2002-04-26 16:49   ` Stan Shebs
  2002-04-26 16:30 ` mike stump
  2002-04-29 22:42 ` Aldy Hernandez
  2 siblings, 1 reply; 11+ messages in thread
From: Joseph S. Myers @ 2002-04-26 16:29 UTC (permalink / raw)
  To: Stan Shebs; +Cc: gcc

On Fri, 26 Apr 2002, Stan Shebs wrote:

> Well, it bit somebody here using almost-3.1 to compile part of
> Mac OS X.  We've been using stdbool.h for some time to provide a
> basic definition of bool, and there is lots of API that makes

When an extension vaguely related to an old draft is replaced by something
following the standard that uses the same syntax, and this breaks Linux
kernel compilation (e.g. compound literals), it doesn't take over a year
for anyone to notice....

> So we're proposing to make _Bool's size target-specific, and
> to add a macro something like BOOL_TYPE_SIZE that can default
> to CHAR_TYPE_SIZE, and that Darwin configs can set to 32.  I'd
> appreciate any comments or feedback on the idea, including
> possible gotchas relating to C++ bool.

The macro exists, and is even documented (for C++).  Since with the new
C++ ABI, mn10200 is the only target where BOOL_TYPE_SIZE !=
CHAR_TYPE_SIZE, the difference between them didn't seem important for C,
so C doesn't currently use the macro.

-- 
Joseph S. Myers
jsm28@cam.ac.uk

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: sizeof (_Bool)
  2002-04-26 15:52 sizeof (_Bool) Stan Shebs
  2002-04-26 16:29 ` Joseph S. Myers
@ 2002-04-26 16:30 ` mike stump
  2002-04-29 22:42 ` Aldy Hernandez
  2 siblings, 0 replies; 11+ messages in thread
From: mike stump @ 2002-04-26 16:30 UTC (permalink / raw)
  To: gcc, shebs

> Date: Fri, 26 Apr 2002 15:48:55 -0700
> From: Stan Shebs <shebs@apple.com>
> To: gcc@gcc.gnu.org

> So we're proposing to make _Bool's size target-specific, and to add
> a macro something like BOOL_TYPE_SIZE that can default to
> CHAR_TYPE_SIZE, and that Darwin configs can set to 32.  I'd
> appreciate any comments or feedback on the idea, including possible
> gotchas relating to C++ bool.

From the C++ frontend:

#ifndef BOOL_TYPE_SIZE
/* `bool' has size and alignment `1', on all platforms.  */
#define BOOL_TYPE_SIZE CHAR_TYPE_SIZE
#endif

  boolean_type_node = make_unsigned_type (BOOL_TYPE_SIZE);
  TREE_SET_CODE (boolean_type_node, BOOLEAN_TYPE);


Would be nice if concepts of bool in C matched the concepts of bool in
C++.  If they don't well, this would be unfortunate.  The code in
decl.c should be in defaults.h for sharing.

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: sizeof (_Bool)
  2002-04-26 16:29 ` Joseph S. Myers
@ 2002-04-26 16:49   ` Stan Shebs
  2002-04-26 17:53     ` Joseph S. Myers
  0 siblings, 1 reply; 11+ messages in thread
From: Stan Shebs @ 2002-04-26 16:49 UTC (permalink / raw)
  To: Joseph S. Myers; +Cc: gcc

"Joseph S. Myers" wrote:
> 
> On Fri, 26 Apr 2002, Stan Shebs wrote:
> 
> > Well, it bit somebody here using almost-3.1 to compile part of
> > Mac OS X.  We've been using stdbool.h for some time to provide a
> > basic definition of bool, and there is lots of API that makes
> 
> When an extension vaguely related to an old draft is replaced by something
> following the standard that uses the same syntax, and this breaks Linux
> kernel compilation (e.g. compound literals), it doesn't take over a year
> for anyone to notice....

When you're a systems company, lead times can be pretty long.
We're also required to support a lot of oddball extensions, so
it takes even longer to get a GCC release into usable shape.

> > So we're proposing to make _Bool's size target-specific, and
> > to add a macro something like BOOL_TYPE_SIZE that can default
> > to CHAR_TYPE_SIZE, and that Darwin configs can set to 32.  I'd
> > appreciate any comments or feedback on the idea, including
> > possible gotchas relating to C++ bool.
> 
> The macro exists, and is even documented (for C++).  Since with the new
> C++ ABI, mn10200 is the only target where BOOL_TYPE_SIZE !=
> CHAR_TYPE_SIZE, the difference between them didn't seem important for C,
> so C doesn't currently use the macro.

But do you think it's a good idea to start using it, or not?

Stan

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: sizeof (_Bool)
  2002-04-26 16:49   ` Stan Shebs
@ 2002-04-26 17:53     ` Joseph S. Myers
  2002-05-02  6:15       ` PATCH " Jason Merrill
  0 siblings, 1 reply; 11+ messages in thread
From: Joseph S. Myers @ 2002-04-26 17:53 UTC (permalink / raw)
  To: Stan Shebs; +Cc: gcc

On Fri, 26 Apr 2002, Stan Shebs wrote:

> > The macro exists, and is even documented (for C++).  Since with the new
> > C++ ABI, mn10200 is the only target where BOOL_TYPE_SIZE !=
> > CHAR_TYPE_SIZE, the difference between them didn't seem important for C,
> > so C doesn't currently use the macro.
> 
> But do you think it's a good idea to start using it, or not?

If the Darwin and mn10200 maintainers agree that, where a non-default size
is used for bool in one of C and C++, it should also be used in the other,
then it would be a good idea to move BOOL_TYPE_SIZE to defaults.h and make
the obvious 1-line change to the C front end to use it there.  (And while
you're about it, get rid of the two definitions of BOOL_TYPE_SIZE to its
default value that are present in other target headers.)

-- 
Joseph S. Myers
jsm28@cam.ac.uk

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: sizeof (_Bool)
  2002-04-26 15:52 sizeof (_Bool) Stan Shebs
  2002-04-26 16:29 ` Joseph S. Myers
  2002-04-26 16:30 ` mike stump
@ 2002-04-29 22:42 ` Aldy Hernandez
  2002-04-30 10:29   ` Dale Johannesen
  2 siblings, 1 reply; 11+ messages in thread
From: Aldy Hernandez @ 2002-04-29 22:42 UTC (permalink / raw)
  To: Stan Shebs; +Cc: gcc

>>>>> "Stan" == Stan Shebs <shebs@apple.com> writes:

 > Since there are now millions of machines out in the field with
 > OS X on them, you can imagine that we're pretty worried about
 > binary compatibility - we don't want Grandma's family pictures
 > trashed by a newly-downloaded iPhoto!

#if 0
Doh!  Forget grandma (http://people.redhat.com/aldyh/grandma/), she
already has her own web page.  What really worries me is my own
traveling pictures are all done with iPhoto
(people.redhat.com/~aldyh/).
#endif

 > So we're proposing to make _Bool's size target-specific, and
 > to add a macro something like BOOL_TYPE_SIZE that can default

uhhh, speak of which... What is apple doing for vector long, or is
that just context sensitive in the front end?  There's been some
recent debate about bool defined to signed in <altivec.h>

aldy

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: sizeof (_Bool)
  2002-04-29 22:42 ` Aldy Hernandez
@ 2002-04-30 10:29   ` Dale Johannesen
  2002-04-30 17:44     ` Aldy Hernandez
  0 siblings, 1 reply; 11+ messages in thread
From: Dale Johannesen @ 2002-04-30 10:29 UTC (permalink / raw)
  To: Aldy Hernandez; +Cc: Dale Johannesen, Stan Shebs, gcc


On Monday, April 29, 2002, at 10:30 PM, Aldy Hernandez wrote:
> uhhh, speak of which... What is apple doing for vector long, or is
> that just context sensitive in the front end?

yes, "vector" is context sensitive.  "vector long" is treated
as in the PIM (including a warning as deprecated, but that's recent).

>  There's been some
> recent debate about bool defined to signed in <altivec.h>

This is also context sensitive in the FE(s), and quite tricky
to get right.  I don't think there's any other way to conform
to the PIM and all the language standards, so if you don't
want to go the context-sensitive route, you'll have to decide
which conformance to give up.

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: sizeof (_Bool)
  2002-04-30 10:29   ` Dale Johannesen
@ 2002-04-30 17:44     ` Aldy Hernandez
  2002-05-02  5:43       ` Jason Merrill
  0 siblings, 1 reply; 11+ messages in thread
From: Aldy Hernandez @ 2002-04-30 17:44 UTC (permalink / raw)
  To: Dale Johannesen; +Cc: Stan Shebs, gcc, jason

> yes, "vector" is context sensitive.  "vector long" is treated
> as in the PIM (including a warning as deprecated, but that's recent).

is is a problem with gcc's current implementation and we can't really
do anything about it until we get a merged front end and get rid of
this __builtin_choose_expr stuff.  right no "vector long" and "vector
int" both map to V4SI (signed) and there's no way to distinguish between
them.

> 
> This is also context sensitive in the FE(s), and quite tricky
> to get right.  I don't think there's any other way to conform
> to the PIM and all the language standards, so if you don't
> want to go the context-sensitive route, you'll have to decide
> which conformance to give up.

i might end up getting rid of bool altogether out of the FSF version,
unless someone can come up with a better solution.

aldy

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: sizeof (_Bool)
  2002-04-30 17:44     ` Aldy Hernandez
@ 2002-05-02  5:43       ` Jason Merrill
  0 siblings, 0 replies; 11+ messages in thread
From: Jason Merrill @ 2002-05-02  5:43 UTC (permalink / raw)
  To: aldyh; +Cc: Stan Shebs, gcc

>>>>> "Aldy" == Aldy Hernandez <aldyh@redhat.com> writes:

>> This is also context sensitive in the FE(s), and quite tricky
>> to get right.  I don't think there's any other way to conform
>> to the PIM and all the language standards, so if you don't
>> want to go the context-sensitive route, you'll have to decide
>> which conformance to give up.

> i might end up getting rid of bool altogether out of the FSF version,
> unless someone can come up with a better solution.

That's what I would advocate.

Jason

^ permalink raw reply	[flat|nested] 11+ messages in thread

* PATCH Re: sizeof (_Bool)
  2002-04-26 17:53     ` Joseph S. Myers
@ 2002-05-02  6:15       ` Jason Merrill
  2002-05-02  8:27         ` Stan Shebs
  0 siblings, 1 reply; 11+ messages in thread
From: Jason Merrill @ 2002-05-02  6:15 UTC (permalink / raw)
  To: Stan Shebs; +Cc: gcc, gcc-patches, Joseph S. Myers

[-- Attachment #1: Type: text/plain, Size: 485 bytes --]

C and C++ bool should absolutely have the same size.  Does this do the
trick for you?

2002-05-02  Jason Merrill  <jason@redhat.com>

	* defaults.h (BOOL_TYPE_SIZE): Move default here from cp/decl.c.
	* c-decl.c (c_init_decl_processing): Use it.
	* config/rs6000/darwin.h (BOOL_TYPE_SIZE): Define to INT_TYPE_SIZE.
	* config/i960/i960.h (BOOL_TYPE_SIZE): Don't define.
	* config/mcore/mcore.h (BOOL_TYPE_SIZE): Don't define.
	* cp/decl.c (BOOL_TYPE_SIZE): Move default to defaults.h.


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: Type: text/x-patch, Size: 3999 bytes --]

*** ./cp/decl.c.~1~	Thu May  2 13:24:12 2002
--- ./cp/decl.c	Thu May  2 12:19:56 2002
*************** Boston, MA 02111-1307, USA.  */
*** 51,61 ****
  
  extern const struct attribute_spec *lang_attribute_table;
  
- #ifndef BOOL_TYPE_SIZE
- /* `bool' has size and alignment `1', on all platforms.  */
- #define BOOL_TYPE_SIZE CHAR_TYPE_SIZE
- #endif
- 
  static tree grokparms				PARAMS ((tree));
  static const char *redeclaration_error_message	PARAMS ((tree, tree));
  
--- 51,56 ----
*** ./c-decl.c.~1~	Thu May  2 13:24:11 2002
--- ./c-decl.c	Thu May  2 12:20:43 2002
*************** c_init_decl_processing ()
*** 3080,3086 ****
    boolean_false_node = integer_zero_node;
  
    /* With GCC, C99's _Bool is always of size 1.  */
!   c_bool_type_node = make_unsigned_type (CHAR_TYPE_SIZE);
    TREE_SET_CODE (c_bool_type_node, BOOLEAN_TYPE);
    TYPE_MAX_VALUE (c_bool_type_node) = build_int_2 (1, 0);
    TREE_TYPE (TYPE_MAX_VALUE (c_bool_type_node)) = c_bool_type_node;
--- 3080,3086 ----
    boolean_false_node = integer_zero_node;
  
    /* With GCC, C99's _Bool is always of size 1.  */
!   c_bool_type_node = make_unsigned_type (BOOL_TYPE_SIZE);
    TREE_SET_CODE (c_bool_type_node, BOOLEAN_TYPE);
    TYPE_MAX_VALUE (c_bool_type_node) = build_int_2 (1, 0);
    TREE_TYPE (TYPE_MAX_VALUE (c_bool_type_node)) = c_bool_type_node;
*** ./config/i960/i960.h.~1~	Thu May  2 14:05:52 2002
--- ./config/i960/i960.h	Thu May  2 14:05:44 2002
*************** struct cum_args { int ca_nregparms; int 
*** 1190,1200 ****
  
  #define SLOW_BYTE_ACCESS 1
  
- /* Force sizeof(bool) == 1 to maintain binary compatibility; otherwise, the
-    change in SLOW_BYTE_ACCESS would have changed it to 4.  */
- 
- #define BOOL_TYPE_SIZE CHAR_TYPE_SIZE
- 
  /* We assume that the store-condition-codes instructions store 0 for false
     and some other value for true.  This is the value stored for true.  */
  
--- 1190,1195 ----
*** ./config/mcore/mcore.h.~1~	Thu May  2 14:03:20 2002
--- ./config/mcore/mcore.h	Thu May  2 14:03:27 2002
*************** extern const char * mcore_stack_incremen
*** 270,278 ****
     words.  */
  #define LONG_LONG_TYPE_SIZE 64
  
- /* the size of the boolean type -- in C++; */
- #define	BOOL_TYPE_SIZE	8
- 
  /* Allocation boundary (in *bits*) for storing arguments in argument list.  */
  #define PARM_BOUNDARY  	32
  
--- 270,275 ----
*** ./config/rs6000/darwin.h.~1~	Thu May  2 14:03:20 2002
--- ./config/rs6000/darwin.h	Thu May  2 14:03:27 2002
*************** Boston, MA 02111-1307, USA.  */
*** 233,235 ****
--- 233,239 ----
     space/speed.  */
  #undef MAX_LONG_TYPE_SIZE
  #define MAX_LONG_TYPE_SIZE 32
+ 
+ /* For binary compatibility with 2.95; Darwin C APIs use bool from
+    stdbool.h, which was an int-sized enum in 2.95.  */
+ #define BOOL_TYPE_SIZE INT_TYPE_SIZE
*** ./doc/tm.texi.~1~	Thu May  2 13:31:39 2002
--- ./doc/tm.texi	Thu May  2 13:03:34 2002
*************** used in @code{cpp}.
*** 1422,1430 ****
  
  @findex BOOL_TYPE_SIZE
  @item BOOL_TYPE_SIZE
! A C expression for the size in bits of the C++ type @code{bool} on the
! target machine.  If you don't define this, the default is
! @code{CHAR_TYPE_SIZE}.
  
  @findex FLOAT_TYPE_SIZE
  @item FLOAT_TYPE_SIZE
--- 1422,1430 ----
  
  @findex BOOL_TYPE_SIZE
  @item BOOL_TYPE_SIZE
! A C expression for the size in bits of the C++ type @code{bool} and
! C99 type @code{_Bool} on the target machine.  If you don't define
! this, and you probably shouldn't, the default is @code{CHAR_TYPE_SIZE}.
  
  @findex FLOAT_TYPE_SIZE
  @item FLOAT_TYPE_SIZE
*** ./defaults.h.~1~	Thu May  2 13:24:11 2002
--- ./defaults.h	Thu May  2 12:19:57 2002
*************** do {								\
*** 285,290 ****
--- 285,295 ----
  #define CHAR_TYPE_SIZE BITS_PER_UNIT
  #endif
  
+ #ifndef BOOL_TYPE_SIZE
+ /* `bool' has size and alignment `1', on all platforms.  */
+ #define BOOL_TYPE_SIZE CHAR_TYPE_SIZE
+ #endif
+ 
  #ifndef SHORT_TYPE_SIZE
  #define SHORT_TYPE_SIZE (BITS_PER_UNIT * MIN ((UNITS_PER_WORD + 1) / 2, 2))
  #endif

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: PATCH Re: sizeof (_Bool)
  2002-05-02  6:15       ` PATCH " Jason Merrill
@ 2002-05-02  8:27         ` Stan Shebs
  0 siblings, 0 replies; 11+ messages in thread
From: Stan Shebs @ 2002-05-02  8:27 UTC (permalink / raw)
  To: Jason Merrill; +Cc: gcc, gcc-patches, Joseph S. Myers

Jason Merrill wrote:
> 
> C and C++ bool should absolutely have the same size.  Does this do the
> trick for you?

Yes, this looks like the right thing.  Thank you!

Stan

> 2002-05-02  Jason Merrill  <jason@redhat.com>
> 
>         * defaults.h (BOOL_TYPE_SIZE): Move default here from cp/decl.c.
>         * c-decl.c (c_init_decl_processing): Use it.
>         * config/rs6000/darwin.h (BOOL_TYPE_SIZE): Define to INT_TYPE_SIZE.
>         * config/i960/i960.h (BOOL_TYPE_SIZE): Don't define.
>         * config/mcore/mcore.h (BOOL_TYPE_SIZE): Don't define.
>         * cp/decl.c (BOOL_TYPE_SIZE): Move default to defaults.h.

^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2002-05-02 15:27 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-04-26 15:52 sizeof (_Bool) Stan Shebs
2002-04-26 16:29 ` Joseph S. Myers
2002-04-26 16:49   ` Stan Shebs
2002-04-26 17:53     ` Joseph S. Myers
2002-05-02  6:15       ` PATCH " Jason Merrill
2002-05-02  8:27         ` Stan Shebs
2002-04-26 16:30 ` mike stump
2002-04-29 22:42 ` Aldy Hernandez
2002-04-30 10:29   ` Dale Johannesen
2002-04-30 17:44     ` Aldy Hernandez
2002-05-02  5:43       ` Jason Merrill

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).