public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
* bool
@ 1997-11-11  8:27 Andrew Borthwick
  1997-11-11 10:52 ` bool Per Bothner
       [not found] ` <199711111843.KAA03525.cygnus.egcs@cygnus.com>
  0 siblings, 2 replies; 9+ messages in thread
From: Andrew Borthwick @ 1997-11-11  8:27 UTC (permalink / raw)
  To: egcs

Hi,

    I'm looking for some advice on boolean variables in g++.  I wrote a little
test program and found that with the 1997/11/05 snapshot, a bool has a size of 4
bytes.  While I recognize that this is not a valid comparison because of the use
of pointers, I found that "sizeof(vector<bool>)" gives a size of 28 bytes as did
"sizeof(bit_vector)".  My questions, then are,

--Am I better off using vector<bool> or bit_vector if I want a vector of
booleans?

--Am I correct that if space is a concern, I am better off using a "char" than a
"bool" because the former takes one byte and the latter takes four?

Thanks,
Andrew Borthwick




^ permalink raw reply	[flat|nested] 9+ messages in thread
* Re:bool
@ 1997-11-11 15:29 Andrew Borthwick
  1997-11-12  2:47 ` bool Branko Cibej
  0 siblings, 1 reply; 9+ messages in thread
From: Andrew Borthwick @ 1997-11-11 15:29 UTC (permalink / raw)
  To: egcs

Per Bothner:
> sizeof(bool) must be one.
> Any other choice will be "unexpected" by reasonable progragrammers.

   I totally agree.  This behavior was certainly unexpected by me.

> Er - what has sizeof to do with how bits are packed?  Obviously, sizeof
> will only tell you the fixed (overhead) size.  If you look at
> bit_vector, you will find that it does use 1 bit per bool.

My apologies for a somewhat poor choice of words on the subject of vector<bool>
vs. bit_vector.

     I'm still not entirely clear.  Am I correct that bit_vector gives me
1 bit per bool but vector<bool> does not?  If this is so, couldn't vector be
easily specialized for vector<bool> to give this functionality in a more
standard fashion?

Thanks,
Andrew Borthwick


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

end of thread, other threads:[~1997-11-12  6:25 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1997-11-11  8:27 bool Andrew Borthwick
1997-11-11 10:52 ` bool Per Bothner
     [not found] ` <199711111843.KAA03525.cygnus.egcs@cygnus.com>
1997-11-11 12:13   ` bool Jason Merrill
1997-11-11 12:28     ` bool Per Bothner
1997-11-11 18:24       ` bool Alexandre Oliva
     [not found]     ` <199711112028.MAA08953.cygnus.egcs@cygnus.com>
1997-11-11 18:44       ` bool Jason Merrill
1997-11-12  5:59         ` bool John Carr
1997-11-12  6:25           ` bool Torbjorn Granlund
1997-11-11 15:29 Andrew Borthwick
1997-11-12  2:47 ` bool Branko Cibej

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).