-----Original Message----- From: Ron Hensley <ron@CROSS.DMV.COM> To: CIRCLE@POST.QUEENSU.CA <CIRCLE@POST.QUEENSU.CA> Date: Tuesday, March 03, 1998 5:21 PM Subject: Re: EVENTS >> 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 You are absolutely right. I was the original coder of that event system. The teleport example was an unfortunate one, since i used that small hack of int being of the same size of (void *), which is very dangerous to use. In fact EVENT should be defined as receiving a (void *). The idea behind (void *) was so that it could receive any king of data however complex it may be. Just build a structure with the info and pass it to the event. The event has just to free the structure in the end. That being so, the teleport event should receive a pointer to a structure holding one int wich would be alocated each time you entered in a room with the teleport flag. Well, I was lazy that day. I would however like to point out one thing, that system is(soon to be was) fast enough for my mud. It was intended to be used with a small number of events. Do not use it with a large amounts of events as it is rather slow to run through all the events in the queue updating everyone. When I change my system i'll upload it to the site. Probably, i'll only change the events.c file, causing no implications on the rest of the mud. Happy coding, Luis Carvalho +------------------------------------------------------------+ | 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