Mail Archives: djgpp/2005/03/04/16:15:21
X-Authentication-Warning: | delorie.com: mail set sender to djgpp-bounces using -f
|
From: | Martin Ambuhl <mambuhl AT earthlink DOT net>
|
User-Agent: | Mozilla Thunderbird 0.9 (Windows/20041103)
|
X-Accept-Language: | en-us, en
|
MIME-Version: | 1.0
|
Newsgroups: | comp.os.msdos.djgpp
|
Subject: | Re: problem with return
|
References: | <1ed DOT 3702603c DOT 2f5a12e3 AT cs DOT com>
|
In-Reply-To: | <1ed.3702603c.2f5a12e3@cs.com>
|
Lines: | 143
|
Message-ID: | <F34Wd.1241$603.984@newsread2.news.atl.earthlink.net>
|
Date: | Fri, 04 Mar 2005 21:04:37 GMT
|
NNTP-Posting-Host: | 165.247.46.67
|
X-Complaints-To: | abuse AT earthlink DOT net
|
X-Trace: | newsread2.news.atl.earthlink.net 1109970277 165.247.46.67 (Fri, 04 Mar 2005 13:04:37 PST)
|
NNTP-Posting-Date: | Fri, 04 Mar 2005 13:04:37 PST
|
Organization: | EarthLink Inc. -- http://www.EarthLink.net
|
To: | djgpp AT delorie DOT com
|
DJ-Gateway: | from newsgroup comp.os.msdos.djgpp
|
Reply-To: | djgpp AT delorie DOT com
|
KTrumpetsRule AT cs DOT com wrote:
> I have a problem I'm having a really tough time tracking down. Below is the
> code. out_xxxx.c calls function cyl_volume() which is in bm_xxxx.c. As I go
> along, I'm checking all the results against a Texas Instruments TI-30Xa
> calculator.
Your posted code (at EOM) is *not* the real code you use.
After making your code into a legal portable program (below), I cannot
reproduce your problem:
[ An attempt to make the code compilable]
#include <stdio.h>
#include <math.h>
#define PI 3.14159265358979323846L
typedef struct
{
double bore, stroke;
double V_1_ci;
} engine_t;
double cyl_volume(engine_t *);
int main(void)
{
double temp;
engine_t eng = { 2.975, 3.23, 0 }, sim = {
0, 0, 0};
engine_t *psim = ∼
temp = 1102290688.;
printf("psim->V_1_ci = %10.6f, temp = %10.6f\n", psim->V_1_ci,
temp);
temp = cyl_volume(&eng);
psim->V_1_ci = temp;
printf("CYLINDER VOLUME - %10.6f cubic inches\n", psim->V_1_ci);
return 0;
}
double cyl_volume(engine_t * peng)
{
double cyl_vol = 0.0;
double temp1 = 0.0, temp2 = 0.0, temp3 = 0.0;
cyl_vol = PI * (pow(peng->bore / 2, 2)) * peng->stroke;
printf("inside cyl_volume()\n");
printf("peng->bore = %10.6f, peng->stroke = %10.6f\n",
peng->bore, peng->stroke);
printf
("peng->bore/2 = %10.6f, pow(peng->bore/2, 2) = %10.6f\n",
peng->bore / 2, pow(peng->bore / 2, 2));
printf("PI = %10.10Lf, cyl_vol = %10.6f\n", PI, cyl_vol);
temp1 = pow(peng->bore / 2, 2);
temp2 = temp1 * peng->stroke;
temp3 = temp2 * PI;
printf("temp1 = %10.6f, temp2 = %10.6f, temp3 = %10.6f\n\n", temp1,
temp2, temp3);
return temp3;
}
[output from this program]
psim->V_1_ci = 0.000000, temp = 1102290688.000000
inside cyl_volume()
peng->bore = 2.975000, peng->stroke = 3.230000
peng->bore/2 = 1.487500, pow(peng->bore/2, 2) = 2.212656
PI = 3.1415926536, cyl_vol = 22.452585
temp1 = 2.212656, temp2 = 7.146880, temp3 = 22.452585
CYLINDER VOLUME - 22.452585 cubic inches
[original poster's "code"]
> THIS IS IN OUT_XXXX.C
> /*
> locate(5,5);
> printf("Computing CYLINDER VOLUME ... ");
> */
> temp = 0.0;
> temp = cyl_volume(&eng_0);
> locate(5,5);
> printf("ptr_sim_0->V_1_ci = %10.6f, temp = %10.6f",
> ptr_sim_0->V_1_ci, temp);
> locate(13,5);
> ptr_sim_0->V_1_ci = cyl_volume(&eng_0); /* this is in bm_xxxx.c
> */
> locate(13,5);
> printf("CYLINDER VOLUME - %10.6f cubic inches", ptr_sim_0->V_1_ci);
> pause(0);
>
> THIS IS IN BM_XXXX.C
> float cyl_volume(ENGINE *ptr_eng_0)
> {
> float cyl_vol = 0.0;
> float temp1 = 0.0, temp2 = 0.0, temp3 = 0.0;
>
> cyl_vol = PI * (pow(ptr_eng_0->bore/2, 2)) *
> ptr_eng_0->stroke;
>
> /* start debug */
> locate(7,5);
> printf("inside cyl_volume()");
> locate(8,5);
> printf("ptr_eng_0->bore = %10.6f, ptr_eng_0->stroke = %10.6f",
> ptr_eng_0->bore, ptr_eng_0->stroke);
> locate(9,5);
> printf("ptr_eng_0->bore/2 = %10.6f, pow(ptr_eng_0->bore/2, 2) = %10.6f",
> ptr_eng_0->bore/2, pow(ptr_eng_0->bore/2, 2));
> locate(10,5);
> printf("PI = %10.10f, cyl_vol = %10.6f", PI, cyl_vol);
> locate(11,5);
> temp1 = pow(ptr_eng_0->bore/2, 2);
> temp2 = temp1 * ptr_eng_0->stroke;
> temp3 = temp2 * PI;
> printf("temp1 = %10.6f, temp2 = %10.6f, temp3 = %10.6f", temp1, temp2,
> temp3);
> return temp3;
> /* end debug */
>
> /* return cyl_vol; */
> }
>
> THIS IS RESULTS ON SCREEN
> ptr_sim_0->V_1_ci = 0.000000, temp = 1102290688.000000
>
> inside cyl_volume())
> ptr_eng_0->bore = 2.975000, ptr_eng_0->stroke = 3.230000
> ptr_eng_0->bore/2 = 1.487500, pow(ptr_eng_0->bore/2, 2) = 2.212656
> PI = 3.1415927000, cyl_vol = 22.452583
> temp1 = 2.212656, temp2 = 7.146879, temp3 = 22.452583
>
> CYLINDER VOLUME - 1102290688.000000 cubic inches
>
> As you can see from the section titles "THIS IS RESULTS ON SCREEN" even though
> temp3 contains the correct value, it doesn't seem to be returned as such. All
> assigned values and computed values check out OK within the cyl_volume()
> function. Again, this is shown by the "RESULTS" screen.
>
> Any help would be appreciated.
>
[Obscenely oversize sig (without sig separator) removed]
- Raw text -