- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
A simple program like this:
void func1(const std::string &name,
const std::string &name2,
double d1, bool use1 = true,
bool refc = false,
double d3 = -1,
bool check1=true){
std::cout <<"d1 "<<<" "<<<" "<<<"check "<<< " ref "<<<" name "<<<" name2 "<
}
int main () {
double d1 = 0.134627;
func1("name1", "name2", d1, d1 );
return 0;
}
As you can see, the 4th parameter is implicitly casted to a bool. I wonder why it doesn't give a warning. I turned on all warnings, the only one says:
remark #1572: floating-point equality and inequality comparisons are unreliable
which actually not directly reflect this case.
Please help.
void func1(const std::string &name,
const std::string &name2,
double d1, bool use1 = true,
bool refc = false,
double d3 = -1,
bool check1=true){
std::cout <<"d1 "<
}
int main () {
double d1 = 0.134627;
func1("name1", "name2", d1, d1 );
return 0;
}
As you can see, the 4th parameter is implicitly casted to a bool. I wonder why it doesn't give a warning. I turned on all warnings, the only one says:
remark #1572: floating-point equality and inequality comparisons are unreliable
which actually not directly reflect this case.
Please help.
Link Copied
7 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
This example doesn't compile with g++ or icpc:
zw.cpp:2: error: expected unqualified-id before & token
zw.cpp:2: error: expected ) before & token
zw.cpp:2: error: expected initializer before & token
so it doesn't resemble C++ sufficiently to check your question on that basis.
zw.cpp:2: error: expected unqualified-id before & token
zw.cpp:2: error: expected ) before & token
zw.cpp:2: error: expected initializer before & token
so it doesn't resemble C++ sufficiently to check your question on that basis.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I changed the code and it is given below:
// u66043.cpp
#include
using namespace std;
void func1(const string &name,
const string &name2,
double d1,
bool use1 = true,
bool refc = false,
double d3 = -1,
bool check1=true)
{
cout << "d1 (double) " << d1 << ", use1 (bool) " << use1 << ", d3 (double)" << d3 << ", check1 (bool) " << check1 << ", refc (bool) " << refc << endl;
//cout << name << endl;
//cout << name2 << endl;
}
int main () {
double d1 = 0.134627;
func1("name1", "name2", d1, 0.1 );
return 0;
}
I can compile the code with Intel C++ compiler in Windows. Implicit conversion from double to bool looks correct to me. If the value of double is zero then we get "fasle", printed as 0. If the value of double is non zero then we get "true", printed as 1.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
You need to include header files. I only pasted a snip of code.
Thanks.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Sorry, that is not my point.
When I compile on Windows using VS compiler, I can get warning like:
warning C4800: 'double' : forcing value to bool 'true' or 'false' (performance warning)
But I don't get any warning from icc, either on Linux or Windows.
When I compile on Windows using VS compiler, I can get warning like:
warning C4800: 'double' : forcing value to bool 'true' or 'false' (performance warning)
But I don't get any warning from icc, either on Linux or Windows.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Quoting - Zhu Wang (Intel)
Sorry, that is not my point.
When I compile on Windows using VS compiler, I can get warning like:
warning C4800: 'double' : forcing value to bool 'true' or 'false' (performance warning)
But I don't get any warning from icc, either on Linux or Windows.
When I compile on Windows using VS compiler, I can get warning like:
warning C4800: 'double' : forcing value to bool 'true' or 'false' (performance warning)
But I don't get any warning from icc, either on Linux or Windows.
It's not a serious performance hit, unless you compile for x87 code, which you wouldn't do if you were interested in performance. Stylistic warnings are available in -Weffc++, but this is too off beat to be covered by those recommendations.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Quoting - Zhu Wang (Intel)
func1("name1", "name2", d1, d1 );
remark #1572: floating-point equality and inequality comparisons are unreliable
remark #1572: floating-point equality and inequality comparisons are unreliable
Thanks,
Jennifer
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thank you. Please let me know when it is adjusted.
Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page