From: Roland Schwarz (roland.schwarz_at_[hidden])
Date: 2007-10-11 10:18:57


Roland Schwarz wrote:
> How do I map my struct to mem avoiding surprise:
>
> foo& f((foo&)(*mem));
>
> I guess this is bad again, as for the very same reasons of unspecified
> behaviour, true? At least I cannot use a static_cast instead of (foo&) cast.

Altough I am not terribly skilled in standards interpretation I think
the following should be safe:

union { mem[]; foo s; };

Now I should be able to access this as mem[0], mem[1], ... from the
writing side, e.g. from a function that fills my buffer, and later
access it with s.a, s.b.

I would be glad if someone more skilled than me could assert my believe.

Roland aka speedsnail