
On Wed, May 28, 2008 at 1:58 AM, Roland Schwarz <roland.schwarz@chello.at> wrote:
I have buffer in terms of char, i.e. char buffer[]. This buffer is not from stream, file or socket. It comes from a fifo in my application. The I want to make use of the buffer as:
if (type == id_foo) { foo& f(*reinterpret_cast<foo*>(&buffer[0])); ... do something with foo ...
}
And I think this is not only ugly but also unnecessary, since foo already might be expressed in terms of char[]. If not, e.g. because foo is not made of unaligned data, I'd prefer a compiler error instead.
I think that there's a strong possibility that violates strong aliasing requirements.
Btw. read(&foo, sizeof(foo)) also will need to do an equivalent of reinterpret cast internally. Doesn't it?
I just think that endian is a fairly general idea that should not be limited to stream, file and socket.
Is there a usage for it outside of I/O though? I can't think of one. Perhaps what's really needed it a "better" (for some criteria I can't elaborate) I/O system...
Yes of course I always can do the reinterpret_cast, but if we can do better, why shouldn't we?
An alternative I can think of would be to not make the bytes[] private.
It has to be public, to be POD.