Subject: Re: [boost] [boost::endian] Summary of discussion #1
From: Tomas Puverle (tomas.puverle_at_[hidden])
Date: 2010-06-02 14:48:26
> The difference is in the error-prone-ness.
> With the typed one, it's free for me to type pun it, and then I pay
> for what I actually read. With swapping, I have a choice of swapping
> everything, and paying for the ones I don't use, or of only swapping
> the ones I do use, and risk either forgetting to swap before reading
> or accidentally swapping twice if I read it twice.
Disagree. It's akin to saying that since some programmers misuse pointers, they
should not exist.
The interface is just as dangerous as forgetting to use the "typed" endian types
in the definition of the structure.
I don't see anything error-prone or bad about the following:
std::size_t width = swap<big_to_host>(hdr.width);
std::size_t height = swap<big_to_host>(hdr.height);
In fact, it's probably more efficient from the point of the view of the
programmer, since if the structure is large (and with images it frequently is!),
they don't have to go and define an entire endian-enabled structure elsewhere.
The code is concise and well-encapsulated.
Second, and more importantly - a lot of the times, the structures which need to
be endian swapped are defined elsewhere, not by you. They are defined in the OS
headers or in the headers of an image library or what not. With the typed
approach, you will need to maintain a parallel structure with the same fields
and layout - now talk to me about error prone!
Finally - I don't see what your point is. I agreed to provide the typed
interface, so feel free to use it. Are you arguing against the inclusion of the
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk