James wrote:

> Ok, this is an easy question...but it's annoying me,
> 
> How do i pass by reference? i want to pass a pointer to a struct into a
> function, have the function modify the pointer to point somewhere else, and
> pass back the new pointer:
> 
> mystruct *pointer, *head;
> 
> void Modify (mystruct *input)
> {
>       Modify_the_pointer; /* i'm dealing with a linked list, so lets say i
>                                                       want it to point to the next 
>one and return
>                                                       the address of that element */
>       input = new_location_in_list;
> }
> 
> void main (void)
> {
>       malloc head;
> 
>       assign some data;
>       make pointer point to head
>       modify (pointer)
>       /* pointer now wants to point to next one */
> }

You have to pass a pointer, e.g.

void Modify (mystruct **input)
{
        Modify_the_pointer;
        *input = new_location_in_list;
}

void main (void)
{
        malloc head;

        assign some data;
        make pointer point to head
        modify(&pointer);
        /* pointer now wants to point to next one */
}

> i've tried doing that but get errors about passing incompatible pointer
> types and making pointers from integers without casting.

The cast errors are unrelated to issues of passing by reference.

-- 
Glynn Clements <[EMAIL PROTECTED]>

Reply via email to