AFAIK, it's the same in C as C++.
A pointer to a pointer is denoted by **
So it would be,
int assign_ch (CHAR_DATA **lhs_ch, CHAR_DATA *mob, CHAR_DATA *ch)
{
if <something>
*lhs_ch = ch;
else
*lhs_ch = mob;
return 1;
}
See the * before the variable within the function dereferences the pointer, so
you
have the char data pointer.
Then you would call it as...
assign_ch(&ch, ...
--Palrich, drunk extraordinare.
----- Original Message -----
From: "Jeremy Hill" <[EMAIL PROTECTED]>
To: <[email protected]>
Sent: Monday, March 29, 2004 9:22 PM
Subject: CHAR_DATA pointer reference in C -- passing pointers by reference
> 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
>
>
>
> --
> ROM mailing list
> [email protected]
> http://www.rom.org/cgi-bin/mailman/listinfo/rom