abs() function is wierd
-
Anybody ever seen this: Using VS.NET 2003 to compile C++ code. App 1 double freq = 6; double newFreq = abs( freq + 0.5 ) + 4; App 2 double freq = 6; double newFreq = abs( freq + 0.5 ) + 4; When compiled App 1 = 0 errors, o warnings App 2 = Warning C4244 conversion from 'double' to 'int', possible loss of data Strange ? But wait there is more ! App 1 Value of newFreq = 10.5 App 2 Value of newFreq = 10 Why does 'App 1' not produce the warning and a different answer ? I am confused. Users. Can't live with 'em, can't kill em!
-
Anybody ever seen this: Using VS.NET 2003 to compile C++ code. App 1 double freq = 6; double newFreq = abs( freq + 0.5 ) + 4; App 2 double freq = 6; double newFreq = abs( freq + 0.5 ) + 4; When compiled App 1 = 0 errors, o warnings App 2 = Warning C4244 conversion from 'double' to 'int', possible loss of data Strange ? But wait there is more ! App 1 Value of newFreq = 10.5 App 2 Value of newFreq = 10 Why does 'App 1' not produce the warning and a different answer ? I am confused. Users. Can't live with 'em, can't kill em!
Are the compiler settings for each exactly the same?
"One must learn from the bite of the fire to leave it alone." - Native American Proverb
-
Anybody ever seen this: Using VS.NET 2003 to compile C++ code. App 1 double freq = 6; double newFreq = abs( freq + 0.5 ) + 4; App 2 double freq = 6; double newFreq = abs( freq + 0.5 ) + 4; When compiled App 1 = 0 errors, o warnings App 2 = Warning C4244 conversion from 'double' to 'int', possible loss of data Strange ? But wait there is more ! App 1 Value of newFreq = 10.5 App 2 Value of newFreq = 10 Why does 'App 1' not produce the warning and a different answer ? I am confused. Users. Can't live with 'em, can't kill em!
From the MSDN website:
C++ allows overloading, so you can call overloads of abs. In a C program, abs always takes and returns an int.
Is that answering your question ? Maybe your second program is compiled as pure C program ?
-
Are the compiler settings for each exactly the same?
"One must learn from the bite of the fire to leave it alone." - Native American Proverb
Yes, the compiler settings are exactly the same for both apps. Wierd eh ? Users. Can't live with 'em, can't kill em!
-
From the MSDN website:
C++ allows overloading, so you can call overloads of abs. In a C program, abs always takes and returns an int.
Is that answering your question ? Maybe your second program is compiled as pure C program ?
I agree, I have checked that abs() has not been overloaded anywhere else in the program, it has not. Wierd eh ? Both programs are compiled as C++ Users. Can't live with 'em, can't kill em! -- modified at 9:04 Thursday 22nd September, 2005
-
Anybody ever seen this: Using VS.NET 2003 to compile C++ code. App 1 double freq = 6; double newFreq = abs( freq + 0.5 ) + 4; App 2 double freq = 6; double newFreq = abs( freq + 0.5 ) + 4; When compiled App 1 = 0 errors, o warnings App 2 = Warning C4244 conversion from 'double' to 'int', possible loss of data Strange ? But wait there is more ! App 1 Value of newFreq = 10.5 App 2 Value of newFreq = 10 Why does 'App 1' not produce the warning and a different answer ? I am confused. Users. Can't live with 'em, can't kill em!
Problem solved ! A co-worker found that was included in StdAfx.h When commented out, both apps perform the same way. Cheers everybody Users. Can't live with 'em, can't kill em!
-
Anybody ever seen this: Using VS.NET 2003 to compile C++ code. App 1 double freq = 6; double newFreq = abs( freq + 0.5 ) + 4; App 2 double freq = 6; double newFreq = abs( freq + 0.5 ) + 4; When compiled App 1 = 0 errors, o warnings App 2 = Warning C4244 conversion from 'double' to 'int', possible loss of data Strange ? But wait there is more ! App 1 Value of newFreq = 10.5 App 2 Value of newFreq = 10 Why does 'App 1' not produce the warning and a different answer ? I am confused. Users. Can't live with 'em, can't kill em!