Greetings ROM list,

In C++, one may use pointer references on complex data types (classes,
particularly).  Here's an example:
List::Node *List::traverse (const int foo, Node * &prev)
{
    ...
}

where the salient bit is the "Node * &prev" part.  This is important if you want
to change 'prev' in the
calling function instead of modifying a pointer copy in the 'traverse' function.

However, I'm pretty sure that I cannot do so in C.  I would like to pass a
CHAR_DATA pointer by
reference to a function where it will be assigned.  Here's a hypothetical
example:

int assign_ch (CHAR_DATA * &, CHAR_DATA *, CHAR_DATA *);

int assign_ch (CHAR_DATA * &lhs_ch, CHAR_DATA *mob, CHAR_DATA *ch)
{
    if <something>
        lhs_ch = ch;
    else
        lhs_ch = mob;

    return 1;
}


However, this results in compilation errors:
mob_prog.c:2408: error: syntax error before '&' token
mob_prog.c:2544: error: syntax error before '&' token

I suppose a possibility would be to have the return type be of CHAR_DATA *, but
I
would like to reserve it for something else.

Is there anything I can do?

- Jeremy



Reply via email to