Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I make gcc generate a warning if I compare doubles?

Tags:

c++

gcc

warnings

I want to catch equality comparisons of doubles in my code and get warnings for them. Is there a GCC warning that will do this?

It's not something that can be easily grepped for in the source code.

like image 538
anio Avatar asked Dec 13 '22 01:12

anio


2 Answers

GCC 4.7.0 has:

gcc --help=warnings

and it produces, amongst many others:

-Wfloat-equal               Warn if testing floating point numbers for equality

(GCC 4.1.2 does not support the extended help; it 'just' has --help. It does have the warning option, though.)

like image 180
Jonathan Leffler Avatar answered Dec 14 '22 14:12

Jonathan Leffler


A quick man gcc reveals this as a likely candidate

    -Wfloat-equal
like image 28
mathematician1975 Avatar answered Dec 14 '22 15:12

mathematician1975