[Hmm, seems I'm making a habit of commenting myself.]
The last example was actually just a special case of a much more generic scenario with stack variables. E.g. this writes "darn!" thrice:
int main() { float f = (mixed) 1; // The cast is only to defeat the compile time type check. if (f != 0) werror ("darn!"); if (f != 0.0) werror ("darn!"); if (f != 1.0) werror ("darn!"); }
The only difference from the case with the integer 0 is that there's no compile time error in the assignment "float f = 0", and that bug is simple to fix.
/ Martin Stjernholm, Roxen IS
Previous text:
2003-09-15 20:55: Subject: float type weirdness
Actually, it's a bit of a grey zone whether 0 (not 0.0) is in the domain of floats. This produces a run time error:
float f; int main() { f = 0; // Wrong type in assignment, expected float, got int. }
While this works and writes "darn!":
int main() { float f = 0; if (f != 0.0) werror ("darn!"); }
But I consider the second case a bug. The only reason it isn't fixed is that it's very hard to do.
Making 0.0 more equivalent with 0 would actually be a way to cover this ugliness, so in that respect it would be a good thing too.
/ Martin Stjernholm, Roxen IS