comp.lang.ada
 help / color / mirror / Atom feed
From: "Eric G. Miller" <egm2.NOSPAM@jps-NOSPAM.net>
Subject: Re: Another ammunition
Date: Tue, 31 Dec 2002 11:43:36 GMT
Date: 2002-12-31T11:43:36+00:00	[thread overview]
Message-ID: <IpfQ9.4953$134.531497@newsread1.prod.itd.earthlink.net> (raw)
In-Reply-To: <aurr5q$dsa$1@s1.read.news.oleane.net>

Jean-Pierre Rosen wrote:
> I know I'm preaching to the choir, but here is another story Ada fans can
> tell to the other guys who say that "language doesn't matter"...
> 
> My son was recently doing an assignment in C, which involved lots of floating
> point computations, and he kept getting inconsistent results. After lots of
> searching, he discovered that NaNs were generated in various places. There
> seemed to be no consistency in the appearing of NaNs: changing optimization
> options, adding intermediate variables in computations, etc. all changed the
> way NaNs were produced.
> 
> Here is what happened: A C function was returning a float, but in some place
> was declared as returning an int. In gcc, a function that returns a float
> leaves the result on the coprocessor stack, NOT on the regular stack.
> Therefore, the return value of the function was not popped off the
> coprocessor stack. And when the coprocessor's stack is full, every floating
> point operation results in NaN....
> 
> It took a week to understand what was happenning. Would not have passed the
> first compilation in Ada. FWIW...

You're right, but I'm sure gcc could have immediately diagnosed the
problem had you turned up the warnings ("conflicting types for...", "previous
declaration of ...").

The fault here is that the C language requires compilers to be very forgiving,
so you have to take explicit actions with compilers to turn warnings into
errors (-Wall -W -O -Werror, for starters).  IME, gcc rarely gives
warnings that are spurious with -Wall (i.e. ignore at your peril).




  reply	other threads:[~2002-12-31 11:43 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-12-31 10:23 Another ammunition Jean-Pierre Rosen
2002-12-31 11:43 ` Eric G. Miller [this message]
2002-12-31 12:57   ` Jean-Pierre Rosen
2002-12-31 16:23     ` Alexander Schreiber
2003-01-02  6:55       ` AG
2003-01-01 16:58         ` Alexander Schreiber
2003-01-07 12:54           ` Peter Hermann
2003-01-07 13:21           ` Richard Riehle
2003-01-11 18:29             ` Alexander Schreiber
2003-01-13  2:11               ` u.r. faust
2003-01-12 12:44                 ` Larry Kilgallen
2003-01-14  1:24                   ` Georg Bauhaus
2003-01-03  9:50         ` Jean-Pierre Rosen
2003-01-03 15:24         ` Stephen Leake
2002-12-31 16:40     ` Warren W. Gay VE3WWG
2003-01-04 20:17       ` David Thompson
2003-01-06 17:39         ` Warren W. Gay VE3WWG
2003-01-06 20:50           ` Stephen Leake
2003-01-06 22:16             ` Warren W. Gay VE3WWG
2003-01-07 18:37               ` Stephen Leake
2003-01-07 21:55                 ` Warren W. Gay VE3WWG
2003-01-01  9:05 ` Michael Erdmann
2003-01-07 13:03   ` Peter Hermann
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox