Run Microsoft Analyzer over dmd source code
Walter Bright
newshound2 at digitalmars.com
Sun Aug 7 10:30:46 PDT 2011
On 8/7/2011 10:11 AM, bearophile wrote:
> It contains FP warnings like the one I have asked for D too. DMD doesn't
> perform certain unsafe FP operations because they and break IEEE conformance,
> but casting a double to float is accepted and regarded "safe" (I am not sure
> of this): lexer.c(2500): warning C4244: 'initializing' : conversion from
> 'double' to 'float', possible loss of data
You mean implicit casting of double to float. Yes, it is accepted without
complaint by dmd. The problem with requiring a cast is a cast is a blunt instrument:
float f;
double d;
...
f = (float) d;
Now, suppose the maintenance guy decides to upgrade f to being a double to get
more precision:
double f;
double d;
...
f = (float) d;
and there's that cast to float he overlooked, sabotaging his upgrade. Even
worse, suppose the type of f or d or both is changed to some user defined type,
like BigFloat? That cast is just going to *cause* a bug, not fix it.
Requiring the programmer to load up on casts is not necessarily making the code
less "bug-prone".
More information about the Digitalmars-d
mailing list