Re: C Unions

From: John McKeon <jmck_at_customsightsound.com>
Date: Mon, 30 Oct 2000 18:53:03 -0500

Hi Mike:

You wrote:
>
> Could anyone explain to a C illiterate how to interpret a C class union?
>

A union in C gives the bytes in question "multiple personalities". As
far as the compiler is concerned the names refer to the same bytes. if
you call

> For example:
>
> -------------------------------------------------
> typedef struct _PROPSHEETPAGE {
> DWORD dwSize;
> DWORD dwFlags;
> HINSTANCE hInstance;
> union {
> LPCSTR pszTemplate;
> LPCDLGTEMPLATE pResource;
> };

        Here you can refer to _PROPSHEETPAGE.pszTemplate or
_PROPSHEETPAGE.pResource and you will get the data at the same
address. If one of the types is larger than the other the larger
number of bytes would be allocated and of course the extra bytes would
be unused when storing a smaller type. But
>
> -------------------------------------------------
> CLASS PROPSHEETPAGE
> VARIABLE dwSize
> VARIABLE dwFlags
> VARIABLE hInstance
> \ union
> VARIABLE pszTemplate
> VARIABLE pResource

this will not work correctly. You need only one variable for each of
the unions (provided the type is covered by four bytes.

And noe the ubiquitous HTH :)

--
John McKeon
jmck_at_customsightsound.com
Received on Mon Oct 30 2000 - 16:08:19 PST

Subscribe to our e-mail list service. It's free for all SwiftForth and SwiftX users!

This archive was generated 09-Feb-2012. Archive updated nightly.