Twisol said:
Better to do things right the second time than wrong the first time, in my opinion. Many development teams actually insist that every warning be treated as an error. That, IMHO, is a very good thing. The compiler usually knows what it's doing, and if it sees something wrong, its usually a good idea to listen.
And that's the problem: anything meaningful the compiler has to say is drowned out by the warnings we've already acknowledged but never fixed.
My major point here is: I get no warnings.
Look:
--------------------Configuration: MUSHclient - Win32 Debug--------------------
MUSHclient.exe - 0 error(s), 0 warning(s)
So there is no drowning out of meaningful warnings by the compiler. I agree with you, if there was.
Twisol said:
... they're not silly. The compiler is asking us: are you sure you want to truncate this value? The cast tells it: yes, we are sure, please truncate this value.
You may be sure, and you may be wrongly sure.
By casting you are throwing away a compiler check - and to boot, possibly casting wrongly, thus throwing away precision.
Look at this:
//----------------------------------------
// world.BlendPixel
//----------------------------------------
static int L_BlendPixel (lua_State *L)
{
CMUSHclientDoc *pDoc = doc (L);
lua_pushnumber (L, pDoc->BlendPixel (
(long) my_checknumber (L, 1), // Blend
(long) my_checknumber (L, 2), // Base
(short) my_checknumber (L, 3), // Mode
my_optnumber (L, 4, 1) // Opacity
));
return 1; // number of result fields
} // end of L_BlendPixel
How can you be sure that the casts are right? You can't be, just looking at it. You need to switch documents to where BlendPixel is defined, and compare argument by argument.
By leaving the casts out, the compiler does the job right.
Look at this code:
void f (long a)
{
a = 2;
}
int main()
{
double b;
f (b);
return 0;
}
I compile that in g++ with max warnings:
$ g++ -Wall -Wextra test.cpp
$
No errors. No warnings. And that reproduces the problem - I am passing a double to a function taking a long.
Can you tell me which warning you get? I would like to look it up.
My position, subject to more information, is the compiler is wrong to give the warning. Not the code being wrong. And if there is a pragma to defeat the annoying warnings (and it only has to be used around these glue routines) that is actually the more correct solution. |