On Mon, 4 Nov 2002, Josh wrote:

> Alright, I was up all night, and finally gave up with a dequeue_event
> function.  Basically my goal was not to have to repeat the code 3 times,
> each for 3 sections of the union of owner of the event.  I just started
> putting in events, so I'm not really good at them yet.  I got the
> idea/inspiration/partial code from Brian excellent about it
> (http://www.daimi.au.dk/~jobo/pages/event_queue.php)  Also, on the site in
> his example for how to use them, he uses a macro to link it locally, i
> wasn't able to do this, I ended up needing a whole function, just for the
> 'CH' version of the link_locally.

[SNIP]

>    if( ( ch = event->owner.ch) != NULL)
>    {
>       prev = ch->event_first;
>    }
>
>    if( ( obj = event->owner.obj) != NULL)
>    {
>       prev = obj->event_first;
>    }
>
>    if( ( room = event->owner.room) != NULL)
>    {
>       prev = room->event_first;
>    }
>
>    if( !room && !obj && !ch )
>    {
>       bug("dequeue event:  no owner.");
>       return;
>    }

You can't do this with a union.

All members of a union share the same memory space.
Only one of them is valid at any time.  In your union, the
value of event->owner.ch will change (and will not be NULL)
if you set event->owner.obj to something!


Dennis



Reply via email to