Help with function parameters...

Discussion in 'C Programming' started by john.coppens@gmail.com, May 10, 2005.

  1. Guest

    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
     
    , May 10, 2005
    #1
    1. Advertising

  2. On Tue, 10 May 2005 wrote:
    >
    > 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
     
    Arthur J. O'Dwyer, May 10, 2005
    #2
    1. Advertising

  3. Malcolm Guest

    <> wrote
    >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.
     
    Malcolm, May 10, 2005
    #3
  4. JohnC Guest

    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
     
    JohnC, May 11, 2005
    #4
  5. Chris Torek Guest

    In article <>
    <> wrote:
    [While examining code and data with a debugger]
    >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).
    --
    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.
     
    Chris Torek, May 11, 2005
    #5
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jonck van der Kogel
    Replies:
    2
    Views:
    1,011
    Jonck van der Kogel
    May 27, 2004
  2. Boris Sargos
    Replies:
    3
    Views:
    426
    Boris Sargos
    Apr 23, 2004
  3. Jason
    Replies:
    2
    Views:
    559
    Jonathan Mcdougall
    May 13, 2006
  4. kito
    Replies:
    2
    Views:
    443
  5. Florian Loitsch
    Replies:
    11
    Views:
    265
    Michael Winter
    Mar 15, 2005
Loading...

Share This Page