Jump to content

  • Log In with Google      Sign In   
  • Create Account

Interested in a FREE copy of HTML5 game maker Construct 2?

We'll be giving away three Personal Edition licences in next Tuesday's GDNet Direct email newsletter!

Sign up from the right-hand sidebar on our homepage and read Tuesday's newsletter for details!


Visual studio 2010 ignore warrning


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
9 replies to this topic

#1 BaneTrapper   Members   -  Reputation: 1224

Like
0Likes
Like

Posted 24 December 2012 - 03:45 PM

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}
The question:
How do i remove warning in "Visual studio 2010" for specified line/lines

Edited by BaneTrapper, 25 December 2012 - 02:16 PM.

Current projects:
The Wanderer, 2d turn based rpg style game

www.gamedev.net/topic/641117-check-up-the-wanderer/


Sponsor:

#2 SiCrane   Moderators   -  Reputation: 9624

Like
2Likes
Like

Posted 24 December 2012 - 04:22 PM

You can use #pragma warning to disable specific warnings. If you want to disable it for just one line you can use #pragma warning(suppress : 4244).

#3 BaneTrapper   Members   -  Reputation: 1224

Like
0Likes
Like

Posted 24 December 2012 - 04:26 PM

You can use #pragma warning to disable specific warnings. If you want to disable it for just one line you can use #pragma warning(suppress : 4244).

Thank you kind sir.


Current projects:
The Wanderer, 2d turn based rpg style game

www.gamedev.net/topic/641117-check-up-the-wanderer/


#4 Khatharr   Crossbones+   -  Reputation: 3030

Like
3Likes
Like

Posted 24 December 2012 - 10:10 PM

int a = 100;

float b = (float)a;


void hurrrrrrrr() {__asm sub [ebp+4],5;}

There are ten kinds of people in this world: those who understand binary and those who don't.

#5 Cornstalks   Crossbones+   -  Reputation: 6991

Like
1Likes
Like

Posted 24 December 2012 - 10:12 PM

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, 24 December 2012 - 10:13 PM.

[ I was ninja'd 71 times before I stopped counting a long time ago ] [ f.k.a. MikeTacular ] [ My Blog ] [ SWFer: Gaplessly looped MP3s in your Flash games ]

#6 BaneTrapper   Members   -  Reputation: 1224

Like
0Likes
Like

Posted 25 December 2012 - 02:13 PM

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, 25 December 2012 - 02:17 PM.

Current projects:
The Wanderer, 2d turn based rpg style game

www.gamedev.net/topic/641117-check-up-the-wanderer/


#7 Satharis   Members   -  Reputation: 1002

Like
1Likes
Like

Posted 26 December 2012 - 02:35 PM

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, 26 December 2012 - 02:36 PM.


#8 BaneTrapper   Members   -  Reputation: 1224

Like
0Likes
Like

Posted 30 December 2012 - 06:31 AM

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.


Current projects:
The Wanderer, 2d turn based rpg style game

www.gamedev.net/topic/641117-check-up-the-wanderer/


#9 Álvaro   Crossbones+   -  Reputation: 13624

Like
3Likes
Like

Posted 30 December 2012 - 06:36 AM

You probably want to use std::floor instead of casting to int.



#10 BaneTrapper   Members   -  Reputation: 1224

Like
0Likes
Like

Posted 30 December 2012 - 06:39 AM

You probably want to use std::floor instead of casting to int.

Learn something new each day, thanks.


Current projects:
The Wanderer, 2d turn based rpg style game

www.gamedev.net/topic/641117-check-up-the-wanderer/





Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS