RE: Damn Unions
- Posted by Derek Parnell <Derek.Parnell at SYD.RABOBANK.COM> Jul 26, 2002
- 388 views
This message is in MIME format. Since your mail reader does not understand this format, some or all of this message may not be legible. ------_=_NextPart_000_01C2350B.5E9EE820 charset=iso-8859-1 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 ================================================================== De informatie opgenomen in dit bericht kan vertrouwelijk zijn en is uitsluitend bestemd voor de geadresseerde. Indien u dit bericht onterecht ontvangt wordt u verzocht de inhoud niet te gebruiken en de afzender direct te informeren door het bericht te retourneren. ================================================================== The information contained in this message may be confidential and is intended to be exclusively for the addressee. Should you receive this message unintentionally, please do not use the contents herein and notify the sender immediately by return e-mail. ================================================================== ------_=_NextPart_000_01C2350B.5E9EE820 Content-Type: application/ms-tnef