Re: question on union



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


.



Relevant Pages

  • Re: WWDC -- MacBook Pro?
    ... ....but once the program has loaded it into its program memory, ... boundaries, int16 are aligned on 2 byte boundaries, int32 are ... people are always able to come up with the compiler ... Case B, same glass, same ice code water.  ...
    (comp.sys.mac.system)
  • Re: Javas performance far better that optimized C++
    ... The compiler is extremely stupid. ... no memory leaks are guaranteed. ... However I have GC in my .NET programming. ... "C.9.1 Automatic Garbage Collection ...
    (comp.lang.cpp)
  • Re: Compiler and How It Handles Scope
    ... VB's compiler isn't really "state of the art" David. ... memory, no matter how many processes map the code into their virtual address ... words, no real distinction is made between Public/Private variables, or even ... > Modules can contain Public and Private variables, ...
    (microsoft.public.vb.winapi)
  • Re: WaitForSingleObject() will not deadlock
    ... Whatever memory values a thread can see when it creates a new thread can ... that later locks the same mutex. ... standardized multithreading library designed to run efficiently on existing ... A C compiler is not required to do this, and it can still be a conforming C ...
    (microsoft.public.vc.mfc)
  • Re: Delphi for XCode?
    ... memory, and that it moves blocks when they are promoted to the next generation, ... Of course you can have the compiler execute e.g. an array of events. ... But what does COM have to do with MY interfaces? ... Mono is using Boehm as well. ...
    (borland.public.delphi.non-technical)