Re: EVENTS

From: Ron Hensley (ron@CROSS.DMV.COM)
Date: 03/03/98


> Just wondering why this was making a pointer from integer without cast ;)
> Here's the structure:
>
> #define EVENT(name) void (name)(void *causer, void *victim, long info)
                                                              ^^^^^^^^^
                                                 Note info is data type long
>
> struct event_info {
>   int ticks_to_go;
>   EVENT(*func);
>   void *causer,*victim;
>   void *info;
     ^^^^^^^^^^^^
   Note here info is type Void Pointer (void *)


> struct event_info *temp;
>
> (temp->func)(temp->causer,temp->victim,temp->info);
                                         ^^^^^^^^
   Here youre passing a void * when the function expects a long int

as the definitio of add event shows:
  void add_event(int delay,EVENT(*func),void *causer,void *victim,void *info)
info is used as a char *, its the 'argument' being passed the the EVENT

Why its defined as a long in structs.h im not sure, but i guess it to be
to do with that teleport event example that code came with. Also I think
its asssuming that the size of a pointer is the same as a size of a long,
thats why it works anyways, course if it was a near pointer and not a
long, youd have problems.

Anyways your fix .. typecasting ..
  (temp->func)(temp->causer,temp->victim,(int)temp->info);

This is in events.c where the event function is actually called.
As when you pass a char buffer, like char *buf, you are actually passing
the address in memory where said buffer is stored, this works, though it
really should be a (void *) here and in structs.h methinks

Then when you write events, you have this info variable, with the
arguments passed to it, however its type int *blink*
What you end up having to do is this:

EVENT(delayed_command) {
  ACMD(do_gen_comm);
  do_gen_comm(CAUSER_CH, (char *)info, 0, SCMD_INFORMATION);
}

That being, type cast the info var back into a (char *)


>
> ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>
> That line creates an error reading:
> passing arg 3 makes integer from pointer without a cast

In these event queus, info is a char *

    *******************************************************************
    *   Ron Hensley                     ron@dmv.com                   *
    *   Network Administrator           http://www.dmv.com/~ron       *
    *                                   PGP Key at WWW Page           *
    *   DelMarVa OnLine                 749-7898 Ext. 403             *
    *******************************************************************


     +------------------------------------------------------------+
     | Ensure that you have read the CircleMUD Mailing List FAQ:  |
     | http://democracy.queensu.ca/~fletcher/Circle/list-faq.html |
     +------------------------------------------------------------+



This archive was generated by hypermail 2b30 : 12/15/00 PST