|
From: Per W. <pw...@ia...> - 2003-03-05 13:19:22
|
I didn't say your code wasn't portable, I just said that it didn't solve
the real problem, which is where the different characters that are stored
where in the integer.
Since the standard doesn't define it, a portable solutions have to perform
an analysis and adapt to compiler and architecture used. We don't know if
the characters are aligned to least and/or most significant bit of the
integer, and we don't know if the first character of the multicharacter
literal is in higher or lower bits relative the second character of the
literal.
/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 2:39:12 =EC=EC
> To: Ioannis Vranos
> Cc: Dev-C++ Mailing List
> Subject: Re: [Dev-C++] Character variables
>
> If I need a set of 100 bits, the bitset implementation is nice, but for
> multicharacter manipulation it doesn't give an improved portability, whil=
e
> it is more code than
>
> (unsigned('a') << 8) | unsigned('b')
>
>
> =3D=3D> Why isn't my code portable?
>
>
> bitset<numeric_limits<char>::digits10 *2>tag('a');
>
> tag<<=3Dnumeric_limits<char>::digits10;
>
> tag&=3Dbitset<numeric_limits<char>::digits10 *2>('b');
>
>
> =3D=3D> It is completely portable.
>
>
> =3D=3D> Yes it is more code than your code above because my code was made=
to be
> portable. The equivalent would be:
>
>
> (bitset<sizeof(unsigned)>('a')<<8) | bitset<sizeof(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.
>
>
> =3D=3D> ?
>
>
> Ioannis Vranos
>
> * Programming pages: http://www.noicys.freeurl.com
> * Alternative URL: http://run.to/noicys
|