Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.c++ > #8114
| From | "JBarleycorn" <jbnh2o@newsnet.org> |
|---|---|
| Newsgroups | comp.lang.c++ |
| Subject | Re: Size of bool unspecified: why? |
| Date | 2011-07-22 17:17 -0500 |
| Organization | A noiseless patient Spider |
| Message-ID | <j0csuo$9dm$1@dont-email.me> (permalink) |
| References | (8 earlier) <98pp2qFroiU2@mid.individual.net> <j08m2h$ch6$1@dont-email.me> <98q5oiFroiU3@mid.individual.net> <j0acoa$h7u$1@dont-email.me> <2ba060fd-d11e-4cda-b0c8-1038a58b6cf6@a31g2000vbt.googlegroups.com> |
"James Kanze" <james.kanze@gmail.com> wrote in message news:2ba060fd-d11e-4cda-b0c8-1038a58b6cf6@a31g2000vbt.googlegroups.com... > On Jul 22, 12:29 am, "JBarleycorn" <jbn...@newsnet.org> wrote: >> Ian Collins wrote: >> > On 07/21/11 07:56 PM, JBarleycorn wrote: >> >> "Ian Collins"<ian-n...@hotmail.com> wrote : >> >>> On 07/21/11 04:28 PM, JBarleycorn wrote: >> >>>> "Ian Collins"<ian-n...@hotmail.com> wrote: >> >>>>> On 07/21/11 12:32 PM, JBarleycorn wrote: > >> >>>>>> How can bools be used in structs if every >> >>>>>> implementation can define it differently? > >> >>>>> The same way ints can be used in structs when every >> >>>>> implementation can define them differently. > >> >>>> You can used fixed-width integers but there is no >> >>>> complementary bool type. bool is unusable in structs in >> >>>> many instances then. Serialization is not a panacea, >> >>>> it's tedium. > >> >>> The only places where sizeof(bool) matters it will be defined. > >> >> The need for fixed-width integers has been proven and >> >> therefore they are in the standard, but then they forget >> >> the past and create a new type and don't consider that >> >> width matters for that type. Either that or they considered >> >> it not useful in the situations where the fixed-width >> >> integers are a boon. They should have specified a width, as >> >> the alternative of having multiple booleans of different >> >> widths isn't practical I believe. > >> > That argument doesn't make sense, given we have fixed with >> > types, why should the with of any natural type be fixed? >> > The analogy with int still applies. If I want a 32 bit >> > signed type, I'll use int32_t. Whether that is an int or a >> > long under the hood is irrelevant. > >> >> A header of an application program can check if fixed-width >> >> integer types are what the program expects and if not, then >> >> adjustments can be made, but with bool, whaddaya going to >> >> do if the size of bool doesn't meet the app's expectations? > >> > Who often have you needed to know the size of bool? What do >> > you do if sizeof(int) isn't what the program expects? > >> Why would anyone expect sizeof(int) to be anything specific? >> int is not an issue. The fixed-width sizes are an issue, but >> you can test for it and do whatever is necessary to maintain >> consistency. > >> > You use a different type. > >> A different numeric type, which there are a number to choose >> from. Who writes a program that doesn't have a header that >> tests for assumptions based upon the platform? > > Who does? In over thirty years of experience in C and C++, I've > yet to see any application which uses such a header. I'm > tempted to say that someone who uses such a header doesn't > understand the basic philosophy behind C and C++. Now we're getting somewhere! You saying that you code against a *"philosophical"* paradigm. The word "religion" will surface soon, I'm sure. Then you can say that my designs are unholy and yours are holy and then the congregation you belong to will ... something. > >> > How is bool different? > >> If bool doesn't meet your expectations, you don't have the option to >> change to a similar type of different width, because there is no >> similar >> type of different width. > > Sure there is: signed char, short, int and long are all similar > types, with potentially different widths. (Don't ask me why > bool is a signed integral type, rather than an unsigned one.) Like I *said*: there is no *similar* type. 1. That C++ bool is a half-assed integral type, adds to its brokeness. 2. Full-blown integral behavior is not *similar* to boolean behavior. (Surely it's signed so it converts to what the standard likes to view as ubiquitous (a broken line of reasoning IMO): int.) > >> You have to change compilers or something. *Or*, avoid bool >> from the get go noting from the start that you can't rely on >> the width of bool. > > Exactly like every other integral type. > I'm not going to repeat myself. If you conveniently want to ignore what I've said before, fine, but don't try to keep the discussion going then just to "listen to your own voice". I'm giving you a convenient platform to propagandize? Fool me once, shame on you, fool me twice, shame on me! >> >> Use an integer of the right size? What's the point of >> >> having a bool at all then if it is likely that some >> >> compiler or version of it doesn't support the needed type? > >> > Again, how often is the size of a natural type important? > >> *Very* often. > > For example? You keep saying it's important, but I've only > encountered the case in a few rare instances. (For starters, it > can't be important in portable code.) > >> > How often in real code do you use a fixed width type? > >> *Very* often. > > Then there's something wrong with your programming style. > >> *Very* much more often than using non-fixed-width integral >> types. > > Then there's something very wrong with your programming style. Contraire: you are limited by your paradigm (or choose to promote it for ulterior reasons). (Or I'm so far ahead of you that you can't even see the dust anymore... Beep! Beep!). > >> > I'm sure I use them more than most because a lot of my work >> > is on embedded platforms or drivers. > >> Well there you go then. > > Drivers are a bit special, but even in drivers, it's not rare to > use the standard types. And of course, unless things have > changed enormously since I was writing drivers, the fixed width > types don't occur in structs. > > [...] >> No, not likely for then bool would be eliminated from a lot of places >> where it could be used to good effect. I think multiple-width boolean >> types can be made to work, but the complexity is not worth it, so >> 1-byte >> bools, even though there may be a performance penalty on most >> platforms, >> are probably the best choice. I have pretty much decided that where a >> "fast bool" is needed it's a profile/optimizaation thing and trying to >> find an optimum boolean type size as the best compromise across a set >> of >> platforms falls into the category of premature optimization. >> Therefore, >> the overriding concern is suitability for use as a struct field. So, >> my >> boolean class uses a 1-byte type as the underlying type. > > That sounds like the most rational decision. Or rather, you use > the bool the implementation gives you, until you need something > faster for your application. 1. The size of C++ bool can't be relied on. 2. C++ bool has brain-damaged behavior (promotion to int). The only reason bool is needed at all is because relational expressions are of type bool. Yes, that broken, brain-damaged little boolean type is inextricably interleaved throughout all C++ source code. :( > (As I've mentionned earlier, I > expect that bool is a single byte on most, if not all, byte > addressed platforms.) > Now it is, but historically, I have an incling, that on all those platforms, bool was synonymous with int. In that case, you have just different versions (old and new) of the compiler and encounter a size change of type (or synonym) bool.
Back to comp.lang.c++ | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Size of bool unspecified: why? "MikeP" <mp011011@some.org> - 2011-07-16 05:33 -0500
Re: Size of bool unspecified: why? BGB <cr88192@hotmail.com> - 2011-07-16 10:02 -0700
Re: Size of bool unspecified: why? James Kanze <james.kanze@gmail.com> - 2011-07-20 13:05 -0700
Re: Size of bool unspecified: why? "JBarleycorn" <jbnh2o@newsnet.org> - 2011-07-20 15:46 -0500
Re: Size of bool unspecified: why? Ian Collins <ian-news@hotmail.com> - 2011-07-21 09:01 +1200
Re: Size of bool unspecified: why? "JBarleycorn" <jbnh2o@newsnet.org> - 2011-07-20 19:32 -0500
Re: Size of bool unspecified: why? Ian Collins <ian-news@hotmail.com> - 2011-07-21 14:46 +1200
Re: Size of bool unspecified: why? "JBarleycorn" <jbnh2o@newsnet.org> - 2011-07-20 23:28 -0500
Re: Size of bool unspecified: why? Ian Collins <ian-news@hotmail.com> - 2011-07-21 16:43 +1200
Re: Size of bool unspecified: why? "JBarleycorn" <jbnh2o@newsnet.org> - 2011-07-21 02:56 -0500
Re: Size of bool unspecified: why? Ian Collins <ian-news@hotmail.com> - 2011-07-21 20:19 +1200
Re: Size of bool unspecified: why? "JBarleycorn" <jbnh2o@newsnet.org> - 2011-07-21 18:29 -0500
Re: Size of bool unspecified: why? Ian Collins <ian-news@hotmail.com> - 2011-07-22 11:40 +1200
Re: Size of bool unspecified: why? "JBarleycorn" <jbnh2o@newsnet.org> - 2011-07-21 22:33 -0500
Re: Size of bool unspecified: why? Ian Collins <ian-news@hotmail.com> - 2011-07-22 15:46 +1200
Re: Size of bool unspecified: why? "JBarleycorn" <jbnh2o@newsnet.org> - 2011-07-21 23:07 -0500
Re: Size of bool unspecified: why? Ian Collins <ian-news@hotmail.com> - 2011-07-22 16:12 +1200
Re: Size of bool unspecified: why? Ian Collins <ian-news@hotmail.com> - 2011-07-31 18:45 +1200
Re: Size of bool unspecified: why? Nick Keighley <nick_keighley_nospam@hotmail.com> - 2011-07-22 00:12 -0700
Re: Size of bool unspecified: why? James Kanze <james.kanze@gmail.com> - 2011-07-22 11:10 -0700
Re: Size of bool unspecified: why? "JBarleycorn" <jbnh2o@newsnet.org> - 2011-07-22 16:52 -0500
Re: Size of bool unspecified: why? Ian Collins <ian-news@hotmail.com> - 2011-07-23 09:55 +1200
Re: Size of bool unspecified: why? James Kanze <james.kanze@gmail.com> - 2011-07-22 11:01 -0700
Re: Size of bool unspecified: why? "JBarleycorn" <jbnh2o@newsnet.org> - 2011-07-22 17:17 -0500
Re: Size of bool unspecified: why? Ian Collins <ian-news@hotmail.com> - 2011-07-23 10:46 +1200
Re: Size of bool unspecified: why? James Kanze <james.kanze@gmail.com> - 2011-07-24 03:48 -0700
Re: Size of bool unspecified: why? Robert Wessel <robertwessel2@yahoo.com> - 2011-07-24 12:40 -0500
Re: Size of bool unspecified: why? James Kanze <james.kanze@gmail.com> - 2011-07-30 11:22 -0700
Re: Size of bool unspecified: why? "Alf P. Steinbach" <alf.p.steinbach:usenet@gmail.com> - 2011-07-31 02:33 +0200
Re: Size of bool unspecified: why? James Kanze <james.kanze@gmail.com> - 2011-07-30 11:34 -0700
Re: Size of bool unspecified: why? "Alf P. Steinbach" <alf.p.steinbach:usenet@gmail.com> - 2011-07-25 04:46 +0200
Re: Size of bool unspecified: why? James Kanze <james.kanze@gmail.com> - 2011-07-21 07:23 -0700
Re: Size of bool unspecified: why? "JBarleycorn" <jbnh2o@newsnet.org> - 2011-07-21 18:52 -0500
Re: Size of bool unspecified: why? James Kanze <james.kanze@gmail.com> - 2011-07-22 11:24 -0700
Re: Size of bool unspecified: why? "JBarleycorn" <jbnh2o@newsnet.org> - 2011-07-22 17:22 -0500
Re: Size of bool unspecified: why? Ian Collins <ian-news@hotmail.com> - 2011-07-23 10:51 +1200
Re: Size of bool unspecified: why? Nick Keighley <nick_keighley_nospam@hotmail.com> - 2011-07-22 00:17 -0700
Re: Size of bool unspecified: why? Robert Wessel <robertwessel2@yahoo.com> - 2011-07-22 04:26 -0500
Re: Size of bool unspecified: why? James Kanze <james.kanze@gmail.com> - 2011-07-21 02:09 -0700
Re: Size of bool unspecified: why? "JBarleycorn" <jbnh2o@newsnet.org> - 2011-07-21 19:11 -0500
Re: Size of bool unspecified: why? James Kanze <james.kanze@gmail.com> - 2011-07-22 11:58 -0700
Re: Size of bool unspecified: why? "JBarleycorn" <jbnh2o@newsnet.org> - 2011-07-22 17:48 -0500
Re: Size of bool unspecified: why? Nick Keighley <nick_keighley_nospam@hotmail.com> - 2011-07-21 08:41 -0700
Re: Size of bool unspecified: why? "JBarleycorn" <jbnh2o@newsnet.org> - 2011-07-21 19:14 -0500
Re: Size of bool unspecified: why? James Kanze <james.kanze@gmail.com> - 2011-07-22 12:01 -0700
Re: Size of bool unspecified: why? "JBarleycorn" <jbnh2o@newsnet.org> - 2011-07-22 17:51 -0500
Re: Size of bool unspecified: why? Noah Roberts <dont@email.me> - 2011-07-20 16:57 -0700
Re: Size of bool unspecified: why? James Kanze <james.kanze@gmail.com> - 2011-07-21 07:29 -0700
Re: Size of bool unspecified: why? "JBarleycorn" <jbnh2o@newsnet.org> - 2011-07-21 19:24 -0500
Re: Size of bool unspecified: why? Ian Collins <ian-news@hotmail.com> - 2011-07-22 12:33 +1200
Re: Size of bool unspecified: why? "JBarleycorn" <jbnh2o@newsnet.org> - 2011-07-21 22:42 -0500
Re: Size of bool unspecified: why? James Kanze <james.kanze@gmail.com> - 2011-07-21 01:59 -0700
Re: Size of bool unspecified: why? "JBarleycorn" <jbnh2o@newsnet.org> - 2011-07-21 19:42 -0500
Re: Size of bool unspecified: why? James Kanze <james.kanze@gmail.com> - 2011-07-22 12:20 -0700
Re: Size of bool unspecified: why? "JBarleycorn" <jbnh2o@newsnet.org> - 2011-07-22 18:21 -0500
Re: Size of bool unspecified: why? Robert Wessel <robertwessel2@yahoo.com> - 2011-07-16 22:23 -0500
Re: Size of bool unspecified: why? "MikeP" <mp011011@some.org> - 2011-07-17 00:07 -0500
Re: Size of bool unspecified: why? Ian Collins <ian-news@hotmail.com> - 2011-07-17 17:15 +1200
Re: Size of bool unspecified: why? "MikeP" <mp011011@some.org> - 2011-07-17 00:24 -0500
Re: Size of bool unspecified: why? Robert Wessel <robertwessel2@yahoo.com> - 2011-07-17 02:02 -0500
Re: Size of bool unspecified: why? "MikeP" <mp011011@some.org> - 2011-07-17 03:02 -0500
Re: Size of bool unspecified: why? Robert Wessel <robertwessel2@yahoo.com> - 2011-07-17 03:23 -0500
Re: Size of bool unspecified: why? "MikeP" <mp011011@some.org> - 2011-07-17 05:36 -0500
Re: Size of bool unspecified: why? "James" <no@spam.invalid> - 2011-07-17 16:24 -0700
Re: Size of bool unspecified: why? "MikeP" <mp011011@some.org> - 2011-07-18 06:49 -0500
Re: Size of bool unspecified: why? "James" <no@spam.invalid> - 2011-07-18 16:46 -0700
Re: Size of bool unspecified: why? Ian Collins <ian-news@hotmail.com> - 2011-07-19 11:59 +1200
Re: Size of bool unspecified: why? "MikeP" <mp011011@some.org> - 2011-07-19 22:18 -0500
Re: Size of bool unspecified: why? "MikeP" <mp011011@some.org> - 2011-07-17 03:04 -0500
Re: Size of bool unspecified: why? Nick Keighley <nick_keighley_nospam@hotmail.com> - 2011-07-22 00:32 -0700
Re: Size of bool unspecified: why? Nick Keighley <nick_keighley_nospam@hotmail.com> - 2011-07-22 00:41 -0700
Re: Size of bool unspecified: why? Juha Nieminen <nospam@thanks.invalid> - 2011-07-17 13:50 +0000
Re: Size of bool unspecified: why? "MikeP" <mp011011@some.org> - 2011-07-18 06:50 -0500
Re: Size of bool unspecified: why? James Kanze <james.kanze@gmail.com> - 2011-07-20 13:06 -0700
Re: Size of bool unspecified: why? Pawel Dziepak <pdziepak@quarnos.org> - 2011-07-21 12:59 +0000
Re: Size of bool unspecified: why? James Kanze <james.kanze@gmail.com> - 2011-07-21 07:11 -0700
Re: Size of bool unspecified: why? "JBarleycorn" <jbnh2o@newsnet.org> - 2011-07-21 19:21 -0500
Re: Size of bool unspecified: why? James Kanze <james.kanze@gmail.com> - 2011-07-22 12:28 -0700
csiph-web