Please look at this:
void test()
{
double x=1.2;
if(!x) cout<<x<<endl;
}
Tested on version 5.10/00
I hope it is bug, not a feature
Please look at this:
void test()
{
double x=1.2;
if(!x) cout<<x<<endl;
}
Tested on version 5.10/00
I hope it is bug, not a feature
This is illegal in C++ (only valid for bool and int).
You should test
Rene
[quote=“brun”]This is illegal in C++ (only valid for bool and int).
You should test
if (x != 0) ..
[/quote]
I think that is perfectly legal in C and therefore in C++ as well.
// g++ notworks.cc -o notworks.exe
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
double notzero = 2.1;
double zero = 0.;
if (notzero)
{
cout << "notzero is not zero" << endl;
} else {
cout << "Zut!" << endl;
}
if (! zero)
{
cout << "zero is zero" << endl;
} else {
cout << "not having a good day" << endl;
}
}
The attached code compiles just fine with g++ and produces
cplager@PointyIII> ./notworks.exe
notzero is not zero
zero is zero
cplager@PointyIII>
notworks.cpp (480 Bytes)
In the current version in CVS (thanks Axel) we have reactivated the code
allowing
if (!x)
when x is a float or double. This protection was introduced when compilers
did not support this feature (including gcc) on 64 bits platforms.
I checked that both gcc and vcc++ are OK on these platforms.
Rene