Topic: Is sizeof(bool) defined by the C++ standard?


Author: wsbjr@kreative.net (Wilfred Boayue Jr)
Date: 1998/01/12
Raw View
The Visual C++ defines a bool as 1 byte. The sizeof a bool on the HP ANSI
compiler is 4 bytes. The HP documentation seems to indicate that a bool
should be 1 byte. Does the standard specify the sizeof bool or is it
implementation specific?
---
[ comp.std.c++ is moderated.  To submit articles: Try just posting with your
                newsreader.  If that fails, use mailto:std-c++@ncar.ucar.edu
  comp.std.c++ FAQ: http://reality.sgi.com/austern/std-c++/faq.html
  Moderation policy: http://reality.sgi.com/austern/std-c++/policy.html
  Comments? mailto:std-c++-request@ncar.ucar.edu
]





Author: shrum@hpfcla.fc.hp.com (Ken Shrum)
Date: 1998/01/13
Raw View
Wilfred Boayue Jr (wsbjr@kreative.net) wrote:
: The Visual C++ defines a bool as 1 byte. The sizeof a bool on the HP ANSI
: compiler is 4 bytes. The HP documentation seems to indicate that a bool
: should be 1 byte.

Pardon the vendor-specific followup:  sizeof(bool) on HP's ANSI compiler
is 1.  Perhaps Wilfred is having a problem with structure padding.

    Ken Shrum
---
[ comp.std.c++ is moderated.  To submit articles: Try just posting with your
                newsreader.  If that fails, use mailto:std-c++@ncar.ucar.edu
  comp.std.c++ FAQ: http://reality.sgi.com/austern/std-c++/faq.html
  Moderation policy: http://reality.sgi.com/austern/std-c++/policy.html
  Comments? mailto:std-c++-request@ncar.ucar.edu
]





Author: "Peter Kulczycki" <Peter.Kulczycki@risc.uni-linz.ac.at>
Date: 1998/01/14
Raw View
Stroustrup says in [The C++ Programming Language, 3rd ed.], p. 75:

1 <= sizeof (bool) <= sizeof (long)


Ken Shrum wrote in message <69g20h$jkv@fcnews.fc.hp.com>...
>Wilfred Boayue Jr (wsbjr@kreative.net) wrote:
>: The Visual C++ defines a bool as 1 byte. The sizeof a bool on the HP ANSI
>: compiler is 4 bytes. The HP documentation seems to indicate that a bool
>: should be 1 byte.
>
>Pardon the vendor-specific followup:  sizeof(bool) on HP's ANSI compiler
>is 1.  Perhaps Wilfred is having a problem with structure padding.
>
>    Ken Shrum
---
[ comp.std.c++ is moderated.  To submit articles: Try just posting with your
                newsreader.  If that fails, use mailto:std-c++@ncar.ucar.edu
  comp.std.c++ FAQ: http://reality.sgi.com/austern/std-c++/faq.html
  Moderation policy: http://reality.sgi.com/austern/std-c++/policy.html
  Comments? mailto:std-c++-request@ncar.ucar.edu
]





Author: Valentin Bonnard <bonnardv@pratique.fr>
Date: 1998/01/16
Raw View
[This news message is cc-ed to Bjarnes]

Peter Kulczycki <Peter.Kulczycki@risc.uni-linz.ac.at> writes:

> Stroustrup says in [The C++ Programming Language, 3rd ed.], p. 75:
>
> 1 <= sizeof (bool) <= sizeof (long)
>
>
> Ken Shrum wrote in message <69g20h$jkv@fcnews.fc.hp.com>...
> >Wilfred Boayue Jr (wsbjr@kreative.net) wrote:
> >: The Visual C++ defines a bool as 1 byte. The sizeof a bool on the HP ANSI
> >: compiler is 4 bytes. The HP documentation seems to indicate that a bool
> >: should be 1 byte.
> >
> >Pardon the vendor-specific followup:  sizeof(bool) on HP's ANSI compiler
> >is 1.  Perhaps Wilfred is having a problem with structure padding.

This isn't garantied, and is false on gcc 2.7.2 for some
systems, where sizeof (long) is 4 and sizeof (bool) is 8.
egcs now reverted to sizeof (bool) <= sizeof (long), but
on other compilers, sizeof (bool) might still be greater
than sizeof (long).

--

Valentin Bonnard                mailto:bonnardv@pratique.fr
info about C++/a propos du C++: http://www.pratique.fr/~bonnardv/
---
[ comp.std.c++ is moderated.  To submit articles: Try just posting with your
                newsreader.  If that fails, use mailto:std-c++@ncar.ucar.edu
  comp.std.c++ FAQ: http://reality.sgi.com/austern/std-c++/faq.html
  Moderation policy: http://reality.sgi.com/austern/std-c++/policy.html
  Comments? mailto:std-c++-request@ncar.ucar.edu
]