14 Sep, 2008, Lobotomy wrote in the 1st comment:
Votes: 0
I've done this before - I've very sure I've done this before - but for the life of me I can't remember at the moment what the correct syntax or method is to do it. What I'm talking about is having a situation in C where you pass a struct variable of some sort in to a function, then modify the variable passed in inside the function so that when the function ends the variable outside the function has been modified according to the instruction. For instance, consider the code:

void foo( EXAMPLE *bar )
{
if( condition )
(this is where the variable pointed to by *bar would be modified - I can't remember the syntax for it.
Like bar = new_bar or something, but isn't there some sort of asterix or ampersand that should be used,
or something?)
}

EXAMPLE *e = something;
foo( e );

In a setup like that, for all intents and purpose, it should very well be possible to modify the value of "e" from within the function foo(). I just don't remember how… :sad:

The reason I'm even doing it this way is to replace the use of a macro I had created for a particular function. I know that I could easily alleviate this situation by changing the function to return the value I want to assign to the variable, then create a macro for the function to hide the assignment part for regular usage; however, that only solves the issue if a single variable is being modified - multiple variable modifications would still be left unresolved, so it's important that I get this figured out.

Any help would be appreciated.
14 Sep, 2008, David Haley wrote in the 2nd comment:
Votes: 0
Do you mean modify the thing e points to, or change what e points to? I.e. – (a) it points to the same object, but that object is changed, or (b) it points to a different object entirely after the function is done.

For (a), you just need to do something like bar->field = "foobar".

For (b), you need to change foo's prototype to be EXAMPLE** bar, and then call it with &e, not just e.

The important distinction here is between (a) the value of the pointer itself and (b) the value of the thing it points to.
14 Sep, 2008, Lobotomy wrote in the 3rd comment:
Votes: 0
Ah, pointer to pointer. That's what I was looking for. Thanks. :smile:
0.0/3