|
Boost : |
From: Dave Dribin (dave-ml_at_[hidden])
Date: 2006-07-20 16:49:23
Hello,
I started a thread on Boost-users about the proposed endian library,
but it's probably more suitable on the dev list. Here's a link to
the thread in the archives:
<http://lists.boost.org/boost-users/2006/07/20887.php>
I see two issues with the library as of 0.5. First, the endian
classes cannot be used in unions. And, second the classes cannot be
used in variable argument lists. I'm attaching a patch to help
resolve both of these issues.
In order to be used in a union, a class must not have any
constructors. However, removing constructors breaks the following code:
big4_t x = 42;
My solution was to provide a static init() method to help in these
situations:
big4_t x = big_t::init(42);
The second problem shows up using varargs. For example, this will
not compile:
printf("x = %d\n", x);
The solution I came up with is to use operator() to get the native
value:
printf("x = %d\n", x());
In my patch, I've also added a check_unions() function to
endian_test.cpp that tests the sizes of unions.
Thanks,
-Dave
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk