floating point warnings, and gcc 4 warnings in general

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi all,

I'm trying to figure out how to get gcc to warn on a specific problem
that we found in our source code.   I've attached a simple test
program that has a few places where floating point precision can
potentially be lost or cause problems.   Specifically:
   1)   Line 12,  returns a double as a float without an explicit
cast - loss of precision.  Would like a warning here.
   2)  Line 19,  same problem, but with fixed point - returns an int
as a short, without a cast - loss of precision, would like a warning
   3)  Line 31,  subtracts a float from a double (the constant is
treated as a double, the variable is explicitly cast as a float.   In
this particular case, as can be seen in the printf on line 34,  pi/2 -
pi/2 does not equal zero.   This seems like it might be harder to
check for, but I'd love to see a warning here as well.

Note that the method on line 15, where I return a double as an int
does have a warning, even without any -W... options:

tryFloat.C: In member function `int Test::getDI() const':
tryFloat.C:15: warning: return to `int' from `const double'
tryFloat.C:15: warning: argument to `int' from `const double'

The man page on gcc 3.4 and above seem to imply that -Wextra should
have checks for these floating point precision problems - however I've
tried gcc 3.3.2, 3.4.x, 4.0.0, and 4.1.1, and no matter how many -W
options I add, -pedantic, -ansi, etc, to make the compile as strict as
possible, I can't get warnings for these floating point problems.
Can anyone point out how to get warnings, or explain why these aren't
candidates for a warning?

Finally, and probably unrelated,  when I used gcc 4.0.0 and 4.1.1, on
RedHat Enterprise 4 (ES), the warnings I do get are formatted badly -
ie, the warning above (from 3.3.2) shows up as:

tryFloat.C: In member function â:
tryFloat.C:15: warning: converting to â from â

I don't know what the â character is, but thats clearly not very
useful.   The gcc 4.1.1 is a freshly compiled install - I compiled it
with RedHat's gcc 3.4.5 using:

Configured with: /usr/src/gcc-4.1.1/configure
--prefix=/usr/local/gcc-4.1.1 --disable-shared --enable-threads=posix
--enable-lang=c,c++

and make bootstrap.   Any ideas on this one?


Thanks very much,

Scott Lipcon

Attachment: tryFloat.C
Description: Binary data


[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux