Boost logo

Boost :

Subject: Re: [boost] [Submission] RawMemory (24-bit integers and runtime-dispatch)
From: Joe Mucchiello (jmucchiello_at_[hidden])
Date: 2011-09-08 13:19:36

>From: Adder <adder.thief_at_[hidden]>

>How would you read the 3 bytes of data into a 32-bit integer ?

With a lot of code I expect your library to mitigate for me. One way:

// little endian

int32_t i = 0;
unsigned char c;
std::istream is = ....
is >> c;
i = c;
is >> c;
i += (c << 8);
is >> c;
i += (c << 16);
if (i & 00800000) i = i | 0xFF000000; // sign extend the result

I assume you can figure out the big endian method. What I don't understand is the question. For many years now people have written code similar to the above to deal with weird file formats. Do you really think is "unheard of" to have to read 3-bytes into a 4-byte integer? What is the point of a Raw Memory library that does not provide simple functions to do this?

>> I wrote:

>> Or a boost::integer::uint24_t.
>Is uint24_t a way to represent an integer in 24 bits and perform
>operations (arithmetic, input/output, etc. -- similarly to using a
>fundamental type) ?

I found it in boost::endian

>> How about:
>> struct foo {
>> int rgb:24;
>> int bar:3;
>> int baz:4;
>> int alpha:1;
>> };
>Forgive me. I believe that this approach is fundamentally wrong.

You don't deal with legacy code much? What do you do with a legacy process that writes struct foo to a file 100 times and then you need to read that file on another system? I can't call up the programmer who made the monstrosity 20 years ago and tell him his approach is fundamentally wrong.

Boost list run by bdawes at, gregod at, cpdaniel at, john at