Help with function parameters...

J

john.coppens

I have a piece of code that calls a function like this:

722 combine_impedance(&el, f);
(gdb) print f
$15 = 12

'el' is a locally defined struct and f is locally defined as double.
One step more gives:

(gdb) s
combine_impedance (el=0x0, f=-30) at chart.c:516
516 {

The parameters are incorrect - I suspect this may have something to do
with
optimization. A few steps more gives:

(gdb) print *el
$18 = {conn = 0, typ = 4, useloss = 0, val1 = 1234, val2 = 0, z0 = 55,
vf = 0,
loss1 = 0, loss2 = 0, mhz1 = 0, mhz2 = 0, ptlst = 0x0, lnlst = 0x0}
(gdb) print f
$19 = nan(0x8000000000000)

*el is now correct, but 'f' isn't. Still optimization problem?

Needless to say, the results from the function are incorrect.

Someone has any idea how to proceed?
JohnC
 
A

Arthur J. O'Dwyer

I have a piece of code that calls a function like this:

722 combine_impedance(&el, f);
(gdb) print f
$15 = 12

I suspect that your C code has an error in line 42; possibly you have
an extra 'z' in the identifier 'wuzzmatuzz'.

Post your code or nobody will be able to help you with it. Also, don't
use Google Groups Beta, or you risk irking a lot of Usenet readers with
your posts' apparent newbieness (wrong quoting levels, "..." in place
of e-mail addresses, etc.). I recommend getting a real newsreader.

-Arthur
please http://www.contrib.andrew.cmu.edu/~ajo/dont-be-evil.html
 
M

Malcolm

I have a piece of code that calls a function like this:

722 combine_impedance(&el, f);
(gdb) print f

Someone has any idea how to proceed?
Personally I can never get any sense out of debuggers. There may be other
people on the group who can use them.

The best debugging tool is the diagnostic printf(). If you suspect your
function has been called with bad parameters, simply print them out on
program entrance (sometimes you need to put an exit() in there to avoid
getting too many printouts).
If the parameters are corrupt, you know that the function itself is probably
OK and something is wrong elsewhere. If they are fine, then print out some
of the local variables at various stages in execution and try to see where
the function is going wrong.
 
J

JohnC

Thanks. I did some printf's and got some interesting results that
pointed me in the right direction.
Though I regularly use gdb, I was really surprised (and confused) about
the weird results I had during this trace. I guess the solution would
be to turn of the optimization before gdb-ing.
Appreciate for the hint.
John
 
C

Chris Torek

The parameters are incorrect - I suspect this may have something
to do with optimization. A few steps more [and the parameter that
was strange earlier is now normal, while that which was normal
earlier is now strange.]

Unfortunately, dealing with debuggers is off-topic in comp.lang.c
(priarily because there is no standard, C or otherwise, for
debuggers, so you need a *.<debugger-name>.* newsgroup). But
see also <http://web.torek.net/torek/c/compiler.html> (the part
about debugging).
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,043
Latest member
CannalabsCBDReview

Latest Threads

Top