FAQ-Question
- From: Till Crueger <TillFC@xxxxxxx>
- Date: Tue, 20 Jun 2006 20:53:26 +0200
Hi,
I stumbled upon the following code to determine byte ordering in the FAQ:
union {
int i;
char c[sizeof(int)];
} x;
/* do stuff */
In this case it seems that the union was used to convert a memory section
from int to char[]. However I've learned that you couldn't use unions to
reinterpret a memory area, because you can't always be sure that the
fields realy do use the same positions. So why is this code portable?
Thanks,
Till
--
Please add "Salt and Pepper" to the subject line to bypass my spam filter
.
- Follow-Ups:
- Re: FAQ-Question
- From: Frederick Gotham
- Re: FAQ-Question
- From: Christopher Benson-Manica
- Re: FAQ-Question
- From: Dann Corbit
- Re: FAQ-Question
- From: Robert Gamble
- Re: FAQ-Question
- Prev by Date: Re: "Numerical Recipes in C" code
- Next by Date: Re: FAQ-Question
- Previous by thread: Lex Question
- Next by thread: Re: FAQ-Question
- Index(es):
Relevant Pages
|