RE: Damn Unions
- Posted by jordah ferguson <jorfergie03 at yahoo.com> Jul 30, 2002
- 401 views
Hi Derek, merci beaucoup! I was hoping you would help me out though yours came through last. Thank you jordah Derek Parnell wrote: > A Structure is the way we let the compiler know how we want a piece of > RAM > used. It describes the layout of the memory area in terms of how the > compiler is supposed to store and fetch bytes from there. A Union is a > way > of letting the compiler know that the same RAM location can be used > (described) in different ways. Normally a given RAM location contains > data > that is used in only one way. However, occasionally there are times when > we > can use the same area in RAM different ways. > > So, > > union { > DWORD dwOemId; > struct { > WORD wProcessorArchitecture; > WORD wReserved; > }; > > is saying that this piece of RAM can be thought of as either a single > DWORD > or a single struct that contains two WORD items. For the purpose of > mapping > this into Euphoria, the key is to locate the item in the union that is > the > longest. This is then used to calculate the offset of the item that > comes > after the union. > > constant -- typedef struct _SYSTEM_INFO { // sinf > -- start of union > SI_dwOemID = 0, -- length 4 > SI_wProcessorArchitecture = 0, -- length 2, offset same as OemId > SI_wReserved = 2, -- length 2 > -- end of union > SI_dwPageSize = 4, -- length 4 > SI_lpMinimumApplicationAddress = 8, -- length 4 > SI_lpMaximumApplicationAddress = 12, -- length 4 > SI_dwActiveProcessorMask = 16, -- length 4 > SI_dwNumberOfProcessors = 20, -- length 4; > SI_dwProcessorType = 24, -- length 4; > SI_dwAllocationGranularity = 28, -- length 4; > SI_wProcessorLevel = 32, -- length 2; > SI_wProcessorRevision = 34, -- length 2; > SIZEOF_SYSTEM_INFO = 36 > > ------------ > hth, > Derek > > ================================================================== > > > ================================================================== > >