Connecting Tech Pros Worldwide Forums | Help | Site Map

Help with function parameters...

john.coppens@gmail.com
Guest
 
Posts: n/a
#1: Nov 14 '05
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


Arthur J. O'Dwyer
Guest
 
Posts: n/a
#2: Nov 14 '05

re: Help with function parameters...



On Tue, 10 May 2005 john.coppens@gmail.com wrote:[color=blue]
>
> I have a piece of code that calls a function like this:
>
> 722 combine_impedance(&el, f);
> (gdb) print f
> $15 = 12[/color]

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/~a...t-be-evil.html
Malcolm
Guest
 
Posts: n/a
#3: Nov 14 '05

re: Help with function parameters...



<john.coppens@gmail.com> wrote[color=blue]
>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?
>[/color]
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.


JohnC
Guest
 
Posts: n/a
#4: Nov 14 '05

re: Help with function parameters...


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

Chris Torek
Guest
 
Posts: n/a
#5: Nov 14 '05

re: Help with function parameters...


In article <1115746611.165848.206310@f14g2000cwb.googlegroups .com>
<john.coppens@gmail.com> wrote:
[While examining code and data with a debugger][color=blue]
>The parameters are incorrect - I suspect this may have something
>to do with optimization. A few steps more [and the parameter that[/color]
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).
--
In-Real-Life: Chris Torek, Wind River Systems
Salt Lake City, UT, USA (40°39.22'N, 111°50.29'W) +1 801 277 2603
email: forget about it http://web.torek.net/torek/index.html
Reading email is like searching for food in the garbage, thanks to spammers.
Closed Thread