Boost logo

Boost :

From: Roland Schwarz (roland.schwarz_at_[hidden])
Date: 2008-05-23 07:05:56


Neil Mayhew wrote:
> This code is still in the vault, but I'd like to see it in the main part
> of boost. What needs to be done to make this happen?
>
> The endian library is exactly what I've been looking for, and I would
> really like to use it in my work, but I can't justify that to my
> colleagues if it's not an official part of boost.

This is an interesting library indeed! Thank you for having this
brought up on the list again.

However I have some concerns about usefulness when it comes to
compiler independence and platform independence.

One of the goals of such a library to be useful (for me at least) would
be to be able to create compiler/platform independent binary files.

I can see two problems here:

1) struct layout.
   The standard gives no provisions for struct layout. So e.g. for

   struct foo {
      big8_t a;
      big32_t b;
   };

   one cannot predict the alignment of the members. (Or am I wrong
   in this respect?)

2) The standard makes no provision for object representation, so
   writing out a bit pattern (which essentially is object
   representation) cannot be guaranteed to be read in on another
   platform. (Irresepective of endianess.) The only way to do
   this is to map object values to a stream of chars.
   One way to implement this mapping is to convert to ASCII
   representation (this is what the standard lib provides), but
   as I believe this is not the only mapping possible.
   I can imagine a mapping to char values that is less computing
   intensive and will resemble binary a little closer.

In an attempt to solve issue 1) I came up with something like:

struct foo
{
  foo(char* begin, char* end)
    : x(begin)
    , y(begin)
    , z(begin)
  {}

  field<int, bigint32_t, 0> x;
  field<short int, bigint16_t, 32> y;
  field<short int, bigint16_t, 48> z;
};

The foo class can be instantiated on a sequence of chars, and the
field proxies perform conversion onto this sequence during access
operations. The last template parameter controls offset (a bit
offset in my case).

The bottom line: For the endian lib to go into boost I really would
want to require it being able to produce platform independent
binary data.

Regards,

-- 
_________________________________________
  _  _  | Roland Schwarz
 |_)(_  | aka. speedsnail
 | \__) | mailto:roland.schwarz_at_[hidden]
________| http://www.blackspace.at

Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk