Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > Help with function parameters...

Reply
Thread Tools

Help with function parameters...

 
 
john.coppens@gmail.com
Guest
Posts: n/a
 
      05-10-2005
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

 
Reply With Quote
 
 
 
 
Arthur J. O'Dwyer
Guest
Posts: n/a
 
      05-10-2005

On Tue, 10 May 2005 http://www.velocityreviews.com/forums/(E-Mail Removed) 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/~a...t-be-evil.html
 
Reply With Quote
 
 
 
 
Malcolm
Guest
Posts: n/a
 
      05-10-2005

<(E-Mail Removed)> 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.


 
Reply With Quote
 
JohnC
Guest
Posts: n/a
 
      05-11-2005
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

 
Reply With Quote
 
Chris Torek
Guest
Posts: n/a
 
      05-11-2005
In article <(E-Mail Removed) .com>
<(E-Mail Removed)> 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 (4039.22'N, 11150.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.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Function versus pointer to function, in context of std::function,huh? Alf P. Steinbach C++ 10 07-27-2011 05:51 AM
Function pointer to void function and int function Giannis Papadopoulos C Programming 5 09-05-2005 09:06 PM
How override ALL function calls? (Is there a "function call function"?) seberino@spawar.navy.mil Python 2 08-01-2005 12:38 PM
write a function such that when ever i call this function in some other function .it should give me tha data type and value of calling function parameter komal C++ 6 01-25-2005 11:13 AM
Passing a C++ object's member function to a C function expecing a function pointer! James Vanns C++ 7 01-21-2004 02:39 AM



Advertisments