
Mailing List Archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [tlug] Portability of Misaligned Data Access . . . . . . .
>>>>> "Joe" == Joe Larabell <fred62@???> writes:
Joe> In the interest of pedantic portability, C already has a
Joe> methor for ensuring that data which must be accessed in
Joe> different ways is aligned correctly:
union u
{
char as_str[ sizeof( double ) + 1 ];
struct s
{
double as_dbl;
char a_null;
};
};
Joe> As confusing as this looks, this should line the double up
Joe> with the first 'n' bytes of the string and match the sizes of
Joe> the two representations on any mahine.
Yeah, but it's a *lot* uglier than that. Remember the header! What
you really need is something like:
union {
struct {
char pad[6];
char input[10];
} namadata;
struct {
union {
struct {
char pad[6];
char header[2];
} prefix;
double align;
}
double payload;
} yakidata;
} do_you_really_expect_to_pull_this_off_interrobang;
and even then there's no guarantee you'll get a packed structure, or
even that sizeof(char) == 1.
I really have to wonder if the format produced by ibrd() really is
struct {
char header[2];
double payload;
}
and not
struct {
char header[2];
char number[8];
}
The former looks like an exceptionally nasty and pointless form of
data torture.
--
School of Systems and Information Engineering http://turnbull.sk.tsukuba.ac.jp
University of Tsukuba Tennodai 1-1-1 Tsukuba 305-8573 JAPAN
Ask not how you can "do" free software business;
ask what your business can "do for" free software.
Home |
Main Index |
Thread Index