On 22/11/2012 23:20, fl wrote:
> Hi,
>
> I once read someone's code. That experienced programmer used a nested definition of simple integer. Now, I obtain a source code from Matlab Simulink Coder, see below please. It is in the same fashion.
>
> For the integer "Out", why they define a struct here?
>
> Could you explain it to me? Thanks.
>
>
>
> ..............
> typedef struct {
> int32_T Out; /* '<Root>/Out' */
> } ExternalOutputs_Hcic1;
>
I cant really explain what the above is trying to do, but we the same
technique for memory management code in Xen.
With page table management, and guests VMs with different memory
management models[1], it is very easy to get one "type" of unsigned long
mixed up with a different "type" of unsigned long.
As a result, we have hidden one of the many types of memory address in a
structure like this, and provided token accesser methods.
The result is more work for the compiler (although identical compiled
output), and a helpful error from the compiler when you accidentally mix
one type with another, as opposed to a subtle memory corruption bug.
[1] Depending on your type of guest, you can choose between PV,
Autotranslate, HAP (EPT/NPT), Shadow and now nested HAP). It leads to
interesting code internally.
~Andrew
|