delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2000/04/22/08:29:09

From: buers AT gmx DOT de (Dieter Buerssner)
Newsgroups: comp.os.msdos.djgpp
Subject: Re: Library problem?
Date: 22 Apr 2000 12:35:22 GMT
Lines: 79
Message-ID: <8dsbvo.3vvpilr.0@buerssner-17104.user.cis.dfn.de>
References: <3900d15d DOT 7050493 AT news DOT telusplanet DOT net>
NNTP-Posting-Host: pec-91-242.tnt4.s2.uunet.de (149.225.91.242)
Mime-Version: 1.0
X-Trace: fu-berlin.de 956406922 8634151 149.225.91.242 (16 [17104])
X-Posting-Agent: Hamster/1.3.13.0
User-Agent: Xnews/03.02.04
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

kalyniuk AT telusplanet DOT net wrote:

[With RIDE]
>So now for some debugging. I watch the variable that my function
>should change, step through the prog and find that the variable does
>not change. It is still zero (as initialized). I can watch other
>variables and see them change so it's not a problem with the debugger.

I don't use RIDE, so I am speculating a bit here.
Debugging code with floating point may be tricky. Gcc seems to
not generate enough debug information, to let the debugger
trace some values all the time. When debugging with gdb, compiling
the source with -ggdb -ffloat-store and linking with -ggdb
can make debugging of floating point code easier.

If you do understand x87 assembly and/or the FPU, inspecting
the FPU registers directly can also help. In gdb use "info float",
in fsdb "ALT-n", don't know about Rhide, sorry. 

An other option is of course, to put a debuggin printf into 
the source.

>In the library is this function
>
>float cyl_ext_force(int press, float bore)
>{
>     float force=0;
>     force=press * (3.1415 * ((bore/2)*(bore/2)));

For debugging, add

    printf("press = %d, bore = %g, force = %g\n", press, bore, force);

>     return force;
>}
>
>In my project source is the following:

I assume, you have a prototype 

float cyl_ext_force(int, float);

in either the source or some included header here. Yes?

>float ext_force=0;
>struct cylinder{
>     float bore;
>     float rod;
>     int press;
>     };
>     struct cylinder cyl_1;
>
>puts("Enter bore size:");
>scanf("%f\n", &cyl_1.bore);

I haven't used scanf for a long time (only sscanf), but I think

scanf("%f", &cyl_1.bore);

should be used here. (Without the "\n")

>puts("Enter working pressure:");
>scanf("%d\n",&cyl_1.press);

See above.

>ext_force=cyl_ext_force(cyl_1.press, cyl_1.bore);
>
>printf("\nExtend force is %.2f lbs", ext_force);

Depending on context you might need

fflush(stdout);

>Why does the value of ext_force never change from zero? Am I
>overlooking something obvious or what?

Seems to work here. Did you try without the library, by
pasting the code in the library directly into the source?

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019