Re: pointers...

From: Peter Ajamian (peter@pajamian.dhs.org)
Date: 09/06/00


This is just basic mailer code for passing references in C, YMMV.  The
macro is not necessary, but just makes it easier to understand in the
function itself (you could just substitute *exit instead of EXIT).

Added lines start with a `+', changed lines start with an `!'.

Mike Redick wrote:

> Here's the relevant code:
>
> redit.c
>
+ #define EXIT *exit
> void redit_disp_exit_menu(struct descriptor_data *d, struct
! room_direction_data *EXIT
> {
>   /*
>    * if exit doesn't exist, alloc/create it
>    */
!   if (EXIT == NULL)
!     CREATE(EXIT, struct room_direction_data, 1);
>
> //set exit_being_worked_on to point to whichever exit the builder has chosen
>    d->exit_being_worked_on = EXIT;
>
>         -snip-
> }
+ #undef EXIT
>
> void redit_parse(struct descriptor_data *d, char *arg)
> {
>                    -snip-
>
> case '5':
>       OLC_VAL(d) = NORTH;
>    d->extra_exit = 0;
!       redit_disp_exit_menu(d, &OLC_EXIT(d));
>       break;
>
>            -snip-
> }

Another trick I like to use at times to make it integrate seamlessly
with existing code is as follows...

append a _f to the function name, and add a * to the refernece variable,
so the following prototype...

void function(char *arg);

becomes...

void function_f(char **arg);

then add the following to the same header file where you define the
function...

#define function(arg) function_f(&(arg))

then you can pass regular char *'s and the macro will reference them for
you automatically.

Regards, Peter


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



This archive was generated by hypermail 2b30 : 04/11/01 PDT