Sign in to follow this  
BaneTrapper

Visual studio 2010 ignore warrning

Recommended Posts

Hello.
I am just being annoyed by a warning and i cant find how to remove them =,= srsly....

Warning :: "warning C4244: 'argument' : conversion from 'int' to 'float', possible loss of data"
Am doing something like this
void setTextPosition(float a, float b); int main(){    setTextPosition(static_cast<int>(posX), static_cast<int>(posY)); //Note posX and posY are floats and i really need to pass int values the setTextPosition is a sfml2.0 function and i don't want to mess with sfml code}
[font=comic sans ms']The question:[/font]
How do i remove warning in "Visual studio 2010" for specified line/lines Edited by BaneTrapper

Share this post


Link to post
Share on other sites

You can also use a proper static_cast:

int a = 100;
float b = static_cast<float>(a); // int to float

Or:

float b = 100.0f;
int a = static_cast<int>(b); // float to int
Edited by Cornstalks

Share this post


Link to post
Share on other sites
You can also use a proper static_cast:
int a = 100;float b = static_cast<float>(a); // int to float
Or:
float b = 100.0f;int a = static_cast<int>(b); // float to int
I am quite unsure, how or what i did different then you, or what you meant by proper usage of static cast.

And if you are referring to "Khatharr" post, then you should quote it, also i don't see anything "Inappropriate" about him mentioning / using c style cast to int.

I used it like this
float posX;float posY;int main(){    setTextPosition(static_cast <int> (posX) ,static_cast <int> (posY) ) ;    return 0;}
EDIT::
I noticed what did you mean...
The code was tipped in the post, and i made a mistake i shall fix that.
Also the whole post messes up the code section when its edited sorry. Edited by BaneTrapper

Share this post


Link to post
Share on other sites

I really don't understand why you're casting floats to ints for a function that takes floats. If you want to change them to whole numbers you should just cast them seperately to remove the ambiguity or use some kind of round function instead of shearing the last bits off by casting. Rounding would actually be better if you're trying to move them closer to a logical position.

 

Often warnings are there for a reason and I'm not sure why people are so apt to disable them when the extra code to disable them could just as easily -fix- the warning.

Edited by Satharis

Share this post


Link to post
Share on other sites
I really don't understand why you're casting floats to ints for a function that takes floats. If you want to change them to whole numbers you should just cast them seperately to remove the ambiguity or use some kind of round function instead of shearing the last bits off by casting. Rounding would actually be better if you're trying to move them closer to a logical position.

 

Often warnings are there for a reason and I'm not sure why people are so apt to disable them when the extra code to disable them could just as easily -fix- the warning.

Reason behind this is:
In the function, if posX and posY are not round numbers the text may appear blurry. Therefore i cast them to int before passing into function to remove occasion of blurry text.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this