Re: question on union
- From: "Roman Mashak" <mrv@xxxxxxxx>
- Date: Wed, 13 Feb 2008 15:32:47 -0800
Hello, Arthur!
You wrote on Tue, 12 Feb 2008 21:59:55 -0800 (PST):
[skip]
Thanks for your explanations.
A> and refers it using
A> u.i = 0x12;
A> u.c[0] = 0x12;
A> the compiler will simply convert them into instructions like this:
A> movl $0x12, _u
A> movb $0x12, _u
A> The compiler uses same symbols for u.i and u.c[0].
A> The reason why they look different in your debugger is that
A> Intel CPUs use little-endian.
A> un.s is placed in memory like this:
A> 0x02 0x01
A> when referred as u.s, it means a short int 0x0102, i.e. s = 0x102
A> when referred as u.c, it means an array of char, {0x02, 0x01}
But both u.i and u.c are placed in memory on the same little-endian machine,
why do they look differently? I can't catch how it is done.
With best regards, Roman Mashak. E-mail: mrv@xxxxxxxx
.
- Follow-Ups:
- Re: question on union
- From: Arthur
- Re: question on union
- References:
- question on union
- From: Roman Mashak
- Re: question on union
- From: Morris Dovey
- Re: question on union
- From: Roman Mashak
- Re: question on union
- From: Arthur
- question on union
- Prev by Date: Re: Faster way to write in a file
- Next by Date: Re: Implementation of recursion in different languages: what happens in the background ?
- Previous by thread: Re: question on union
- Next by thread: Re: question on union
- Index(es):
Relevant Pages
|