confusion while debugging
Posted: Fri Dec 15, 2006 12:50 am
I was having trouble debugging some hoc code, so finally I just copied the whole thing into another file (Debug.hoc, at the bottom of post) so I could remove everything that wasn't involved and isolate the problem. After lots of massaging, I pared the code down to the following example that demonstrates the problem. When I run the code in nrniv, I get this output:
oc>xopen("./Debug.hoc")
when initialized at beginning of template, n = 100
init(): was called
before reassigning n to 10, n = 0
after reassigning n to 10, n = 10
do_something(): was called
while doing_something, n = 0
do_something(): is finished
after doing_something, n = 0
init(): is finished
1
oc>
The first problem is that even though I initialize n to 100 at the beginning of the template, in init() it is 0.
The second problem is that once n is set to 10 in init(), calling do_something() sets it to 0 again. This doesn't happen if I remove the "objref o" line in do_something, or if I remove either "a = 0" or "b = 0".
I'm running:
NEURON -- Release 5.9.10 (1601) 2006-11-01
on a rather idiosyncratic Rev A Macbook Pro.
Debug.hoc
**************************************
begintemplate Debug
a = 0
b = 0
n = 100
proc init() {
print "init(): was called"
print "before reassigning n to 10, n = ", n
n = 10
print "after reassigning n to 10, n = ", n
do_something()
print "after doing_something, n = ", n
print "init(): is finished"
}
proc do_something() {
objref o
print "do_something(): was called"
print "while doing_something, n = ", n
print "do_something(): is finished"
}
print "when initialized at beginning of template, n = ", n
endtemplate Debug
objref dbg
dbg = new Debug()
**************************************
oc>xopen("./Debug.hoc")
when initialized at beginning of template, n = 100
init(): was called
before reassigning n to 10, n = 0
after reassigning n to 10, n = 10
do_something(): was called
while doing_something, n = 0
do_something(): is finished
after doing_something, n = 0
init(): is finished
1
oc>
The first problem is that even though I initialize n to 100 at the beginning of the template, in init() it is 0.
The second problem is that once n is set to 10 in init(), calling do_something() sets it to 0 again. This doesn't happen if I remove the "objref o" line in do_something, or if I remove either "a = 0" or "b = 0".
I'm running:
NEURON -- Release 5.9.10 (1601) 2006-11-01
on a rather idiosyncratic Rev A Macbook Pro.
Debug.hoc
**************************************
begintemplate Debug
a = 0
b = 0
n = 100
proc init() {
print "init(): was called"
print "before reassigning n to 10, n = ", n
n = 10
print "after reassigning n to 10, n = ", n
do_something()
print "after doing_something, n = ", n
print "init(): is finished"
}
proc do_something() {
objref o
print "do_something(): was called"
print "while doing_something, n = ", n
print "do_something(): is finished"
}
print "when initialized at beginning of template, n = ", n
endtemplate Debug
objref dbg
dbg = new Debug()
**************************************