[Mono-list] Re: Embedded Mono queries

H.W.Thomas Hywel@controlspecials.demon.co.uk
Wed, 6 Mar 2002 09:47:46 -0000


>> 1)  How to link a class's field names to hardware addresses.  The I/O
>> drivers will update a common
>> memory area with current input data values, and I want to know how to
make
>> these addresses available
>
>You can use `structs' instead of classes.  And then code them like this:
>
>[StructLayout (LayoutKind.Explicit)]
>struct CgSixControl {
>	[FieldOffset (0)] int control_register;
>	[FieldOffset (4)] int video_mode;
>	[FieldOffset (8)] int dma_mapping;
>}
>
>Then you can create pointers to your CgSixControl struct, and just
>poking at the values there will go to the right offset.

Many thanks. I hadn't come across the StructLayout attribute before. Will
this information be used by the compiler to generate the offsets in the
IL code, or is it passed on to the runtime to sort out? The "C# Essentials"
book says "..the difference is a C# program finds this offset by looking it
up using the field name; C field names are compiled directly into offsets"

Regards,

Hywel Thomas
Control Specialists Ltd, UK