Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

kaostika

DI8 issue: const int truncated to char using DIK_UP or DIK_UPARROW

This topic is 5878 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I am using Jim Adam''s input core as a basis and am getting this warning (I have read up on it at MSDN: it tells me nothing) warning C4305: ''argument'' : truncation from ''const int'' to ''char'' warning C4309: ''argument'' : truncation of constant value Which in my app renders the UP arrow useless, as well as the other arrow keys. MSDN says that this means I have truncated constant value. That is not helpful at all. I would post the code here but there is alot. Any thoughts on how to get around this?

Share this post


Link to post
Share on other sites
Advertisement
Do you mean using (int)KEY_UP or (const int)KEY_UP or some such? If so then yes I have done that and achieved the same results. Perhaps you could be more specific?

Share this post


Link to post
Share on other sites
Here is the code that is freaking:
// doesn't work, generates error
if(App->m_Keyboard.GetKeyState(KEY_UP) == TRUE) {
XMove = (float)sin(App->m_Camera.GetYRotation()) * 33;
ZMove = (float)cos(App->m_Camera.GetYRotation()) * 33;
}
//works fine, generates no errors
if(App->m_Keyboard.GetKeyState(KEY_S) == TRUE) {
XMove = -(float)sin(App->m_Camera.GetYRotation()) * 33;
ZMove = -(float)cos(App->m_Camera.GetYRotation()) * 33;
}

The actual code for handling the keyboard input is from Jim Adams book so I'm reluctant to post that.

Edit:
Jim's code works fine, as I've tested it in other methods.
KEY_UP is :
#define KEY_UP DIK_UP

so far no other keys, just the arrow keys and RCTRL have this issue.

[edited by - kaostika on April 19, 2002 3:15:27 PM]

Share this post


Link to post
Share on other sites
Look in the back of the book under setting up the compiler, by default chars are unsigned you have to add /j, in the compiler settings i think it is to tell the compiler that its a signed char.

Share this post


Link to post
Share on other sites
DOH! You are correct Blackdragon666. That was the problem. The sad part is I actually read that yesterday and it didn''t dawn on me. Thank you.

Share this post


Link to post
Share on other sites
Well, all you had to do was to cast those const int s to char s—because whatever function you're calling expects char (or unsigned char, if that's the case). Whether or not char s are signed, they'll be smaller than int s on all current Win32 platforms, resulting in truncation. If you follow Blackdragon666's advice and also increase the warning level, you might start seeing those warnings. But you should favor just casting the data in question, instead of making a global change to your program (changing the nature of a fundamental data type, though it probably won't have any major side-effects).

[edited by - merlin9x9 on April 19, 2002 3:56:19 PM]

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!