Page 1 of 1

hoc pointer to variable

Posted: Wed Oct 13, 2010 1:22 pm
by pfortier
I'd can't seem to get Pointer(&x) to work. I tested

objref arrow
age=33
arrow = Pointer(&age)

but it doesn't work. I'm testing it to see if I can use it. Ultimately, I'm trying to find a way to have an array with elements that point to different variables (defined in hoc or mod files) so that I can loop through the array and call k=arrow.val or arrow.val=k. In C, it would be something like (my C is a bit rusty)

double * arrow[12]
double age=33
arrow[0]=&age

Re: hoc pointer to variable

Posted: Thu Oct 14, 2010 11:08 am
by ted
I'm trying to find a way to have an array with elements that point to different variables (defined in hoc or mod files) so that I can loop through the array and call k=arrow.val or arrow.val=k. In C, it would be something like (my C is a bit rusty)

double * arrow[12]
double age=33
arrow[0]=&age

Presumably you have some larger goal that you wish to achieve through the technique of using an array of pointers to iterate through a collection of variables. Unfortunately, this technique is not available to you in hoc, because:
1. hoc doesn't have a * operator. POINTER is an NMODL keyword, not a hoc keyword.
2. hoc's & is used for only two purposes: to pass a scalar argument by reference to a proc or func, and to linking a hoc scalar to a POINTER variable in an NMODL-specified density mechanism, point process, or artificial spiking cell

That said, there are many ways to skin a cat, so I am sure there is some other way to achieve your larger goal. Without knowing anything about that goal, I can't get into particulars.