|
From: Per W. <pw...@ia...> - 2003-03-05 12:40:33
|
If I need a set of 100 bits, the bitset implementation is nice, but for
multicharacter manipulation it doesn't give an improved portability, while
it is more code than
(unsigned('a') << 8) | unsigned('b')
The problem is still that depending on machine and compiler I might have
to do
(unsigned('b') << 8) | unsigned('a')
or
(unsigned('a') << 24) | unsigned('b')
or
(unsigned('b') << 24) | unsigned('a')
or
...
instead, because there isn't a defined standard how the individual
characters should be stored in the integer.
/Per W
On Wed, 5 Mar 2003, Ioannis Vranos wrote:
> -------Original Message-------
>
> From: Per Westermark
> Date: =D4=E5=F4=DC=F1=F4=E7, 5 =CC=DC=F1=F4=E9=EF=F2 2003 1:29:06 =EC=EC
> To: Ioannis Vranos
> Cc: Dev-C++ Mailing List
> Subject: Re: [Dev-C++] Character variables
>
> No, multicharacter literals they are not specifically indented for
> wchar_t.
>
> They are defined to be of type int, and if you want store multiple char
> characters, you write:
> int i =3D 'abcd'
> and for wchar_t
> int i =3D L'ab'
> where a 32-bit integer only have room for two wide characters.
>
>
> =3D=3D> Yes but their meaning is implementation defined. I do not know mu=
ch for
> them, and have only met them in one paragraph in TC++PL up to now that i =
am
> on chapter 19.
>
>
>
>
> The problematic non-standard issue with multicharacter literals is that
> you are not guaranteed to know byte order of the machine, and the order
> the multiple characters are stored in the integer, so you have to do some
> condintional compilation if you want to save/load them.
>
> You might have to do something like
> #if '1234' =3D=3D 0x31323334L
> // init alternative 1
> #elseif '1234' =3D=3D 0x34333231L
> // init alternative 2
> #else
> // no known byte order
> #endif
>
> Even if you use bitset, you still have to check which character goes into
> the high bits, and which character goes to the low bits of the integer.
>
>
> =3D=3D> Personally i can't find any use of them, if you want to add them =
in
> specific order in a bitset you can do:
>
>
> bitset<numeric_limits<char>::digits10 *2>tag('a');
>
> tag<<=3Dnumeric_limits<char>::digits10;
>
> tag&=3Dbitset<numeric_limits<char>::digits10 *2>('b');
>
>
> (i made a mistake in a previous email where i combined 2 different bitset
> types (bitset<32> with bitset<4>).
>
>
> PS - thx for the pdf reference, I haven't had access to a
> computer-readable edition before :-)
>
>
> =3D=3D> Yes, all standards now come in .pdf form. It's the same .pdf as s=
old
> from ISO web site.
>
>
> Ioannis Vranos
>
> * Programming pages: http://www.noicys.freeurl.com
> * Alternative URL: http://run.to/noicys
|