Prev: Simple beginners program
Next: Is union really useful in C++ considering that there is reinterpret_cast?
From: leonleon77 on 11 Jan 2010 02:32 On Jan 9, 12:28 pm, Nick Hounsome <nick.houns...(a)googlemail.com> wrote: > Firstly the type is "unsigned char" not "unsigned very short int" and > char is short for character so I would expect a character to be output > not an integer. Interesting. Given the above are we then to state the following: 1) given that we have (from standard? or may be I am wrong here): "For unsigned character types, all possible bit patterns of the value representation represent numbers." Do you then mean that "numbers" from above do not imply integers, but are rather semantically closer to characters? I would have thought that "numbers" esp. in the context of printing/ output would be closer relatives to integers rather than characters... but may be I am getting myself confused... wouldn't be the first time :-) 2) there is no 1-byte unsigned integer representation in language as per it's standard? > > Or does it have something to do with this: > > "In any particular implementation, a plain char object can take on > > either the same values as a signed char or an unsigned char; which one > > is implementation-defined." ? > > Indeed - And by your reasoning that would make the output of signed/ > unsigned char implementation-defined too since one of them would have > to output as a character but which one? > Ok, indeed, but then how does the above reconcile with the: "For unsigned character types, all possible bit patterns of the value representation represent numbers." a number can be more of a char rather than int? kind regards Leon. -- [ See http://www.gotw.ca/resources/clcm.htm for info about ] [ comp.lang.c++.moderated. First time posters: Do this! ]
From: leonleon77 on 11 Jan 2010 02:30
On Jan 9, 12:28 pm, Nick Hounsome <nick.houns...(a)googlemail.com> wrote: > On Jan 8, 1:39 pm, leonleon77 <leonleo...(a)gmail.com> wrote: > > Or does it have something to do with this: > > "In any particular implementation, a plain char object can take on > > either the same values as a signed char or an unsigned char; which one > > is implementation-defined." ? > > Indeed - And by your reasoning that would make the output of signed/ > unsigned char implementation-defined too since one of them would have > to output as a character but which one? I am also just wondering -- when the aforementioned quote talks about taking on "the same value" -- the word "value" -- could it be w.r.t. bitwise representation only... or it is both -- bitwise representanion and it's semantics (i.e. value vs value-interpretation thingy... where 97 could have the same binary value as 'a' but different semantics)... In other words, could one have different interpretation (and subsequent representation during printing) of the same value and still comply with the above quote? So that a plain char and let's say "it's signed sibling of the same value" could well have identical bitwise form, but different contextual meaning -- much like other cases of strong-typed casting/ treatement of variables and their types in C++ (where bitwise representation is != semantics) ? -- [ See http://www.gotw.ca/resources/clcm.htm for info about ] [ comp.lang.c++.moderated. First time posters: Do this! ] |