Boost logo

Boost :

From: Martin Bonner (martin.bonner_at_[hidden])
Date: 2006-10-17 04:24:37


From: Johan Råde

>
> I'm a bit worried about the whole endianness issue.
> There are three approaches:
>
> 1. Check endianness during compile time (using
> boost/detail/endian.hpp)
[snip]
>
> It would be nice to get 1 to work. There are some problems, but are
> they real or theoretical?

Two problems I know of:
1. The endianness of int and that of float is not necessarily the same (the classic example of this is the Vax). Does Boost support Vax? Are there any other platforms out there that Boost supports which have the same problem?

Of course, this is not a particularly difficult problem to solve. endian.hpp can set another symbol to signal the endiannes of floating point nubmers. By default this would be set to the same as the endianness of int on the platform, but problem platforms could set it seperately.

2. Processors which can switch endianness at runtime. Are there any operating systems which actually allow this, or is a given processor/os combination a fixed endianness?

One solution that you did not suggest:
- Have a global variable that indicates the endianness.
- Initialize it to zero.
- At the start of each function, have the code:
        if (endianness == 0) calculate endianness
        ...
        use endianness
(I think this is safe in practise for multi-threaded operations. It just means that two threads might end up setting the endianness, but as they would both calculate the same value, that hardly matters).
        
Is this the sort of problem which Fusion can solve? Use a compile-time solution where available, or a run-time solution where not.

-- 
Martin Bonner
Martin.Bonner_at_[hidden]
Pi Technology, Milton Hall, Ely Road, Milton, Cambridge, CB24 6WZ,
ENGLAND Tel: +44 (0)1223 203894

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