Click here to Skip to main content

Wong Shao Voon - Professional Profile

31,204
Author
554
Authority
1,139
Debator
195
Editor
20
Enquirer
185
Organiser
1,439
Participant
30 Mar 2012: Best C++ article of February 2012
26 Oct 2009: Best C++/MFC article of Sep 2009
I guess I'll write here what I does in my free time, than to write an accolade of skills which I currently possess. I believe the things I does in my free time, say more about me.
 
When I am not working, I like to watch Japanese anime. I am also writing some movie script, hoping to see my own movie on the big screen one day.
 
I like to jog because it makes me feel good, having done something meaningful in the morning before the day starts.
 
I also writes articles for Codeproject; I have a few ideas to write about but never get around writing because of hectic schedule.
Member since Monday, November 25, 2002 (9 years, 6 months)

For more information on Reputation please see the FAQ.
 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
  Refresh
General[coderant] Zero warnings : An ideal? Pin
Sunday, March 16, 2008 11:15 PM
Some coding books advocate zero warnings at the highest warnings level setting. Is this possible? I think not. I have seen some people resolved “conversion from 'double' to 'float'” warning by doing a float cast. They could have solve this problem by using all floats or all doubles, however we do use libraries, we do not have control over some libraries, especially third party libraries. For example,
 
float m_f;
m_f = (float *)a_double;
 
The problem is by doing a cast, you are silenting the compiler by saying, “yes I know it is wrong but I am very sure a_double's value will not exceed a float's value.” On closer examining the class and library it is using, it only has 2 float member variables and all the casting from double are to be assigned to these 2 member variables. What I seen to be the more correct way to solve this problem, other than casting, is make these 2 variables to be doubles type. Anyway, converting 2 floats(32 bits type) into 2 doubles(64 bits type), you only increase the memory requirement by 8 bytes. It is also much simpler than adding all the castings which need to be there.
 
So the correct way of solving the “conversion from double to float”, “conversion from int to short” and “< : signed/unsigned mismatch” is to change the type of variable to match the other type, ie if that is possible. For example,
 
// Wrong way
for( int i=0; i<(int)vec.size(); ++i ) {
....
}
 
// Correct way: size_t is the same unsigned type as vec.size() returns
for( size_t i=0; i<vec.size(); ++i ) {
....
}
 
If you use casting to resolve these type mismatch warning, you might as well use pragmas to silent the warnings, that is what pragmas are used for! When something has gone wrong and you cannot figure it out why, you can remove the pragmas and re-enable the warnings back. With casting, you can't!
 
Zero warnings to me, is an “hard to achieve” ideal because things are not always clear cut. I will always try my best to reduce warnings to the minimum, but I would rather leave some unresolvable warnings there, so that I know where to look if something goes wrong.
 
<div class="ForumMod">modified on Monday, March 30, 2009 5:52 AM</div>
GeneralRe: [coderant] Zero warnings : An ideal? Pinmember Vasudevan Deepak K0:36 17 Mar '08  

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   


Advertise | Privacy | Mobile
Web01 | 2.5.120528.1 | Last Updated 28 May 2012
Copyright © CodeProject, 1999-2012
All Rights Reserved. Terms of Use
Layout: fixed | fluid