Handmade Hero » Forums » Code » Win32ProcessPendingMessages comparing uint32 with const char *
judgebread
2 posts
#14403 Win32ProcessPendingMessages comparing uint32 with const char *
6 months, 3 weeks ago Edited by judgebread on March 3, 2018, 6:15 p.m. Reason: Initial post

Hi, I was looking into win32_handmade.cpp to see how Casey handles keypresses. I used the code below, but for some reason this does not compile for me (using cl.exe x64 version 19.12 on windows 10).

1
2
3
4
5
6
uint32 VKCode = (uint32)Message.wParam;
...
    if(VKCode == 'W')
    {
        Win32ProcessKeyboardMessage(&KeyboardController->MoveUp, IsDown);
        ...


If I try to compile this I get the following error: error C2446: '==': no conversion from 'const char *' to 'uint32_t'. Looking at the code above, I can completely understand why the compiler complains.

Am I missing something here? How come it works on Casey's machine?
insofaras
Alex Baines
40 posts / 1 project
#14404 Win32ProcessPendingMessages comparing uint32 with const char *
6 months, 3 weeks ago

If you mean line 3, then that's comparing a uint32 with a char (not const char*) since it's using single quotes around the W.

That should be fine and shouldn't cause the error you're seeing. Maybe the error is from a different line, or you accidentally typed the W with double quotes?
judgebread
2 posts
#14405 Win32ProcessPendingMessages comparing uint32 with const char *
6 months, 3 weeks ago

Yup. I was using double quotes. Didn't know single and double quotes mean different things in C++. Thanks for clarifying!
Telash
Mikael Johansson
93 posts / 1 project
#14406 Win32ProcessPendingMessages comparing uint32 with const char *
6 months, 3 weeks ago

Double quotes are used for strings, single for chars.

So if char* word = "a";

Then: word[0] == 'a' will be true.
word == 'a' will be false.

word is just an adress to an array here.

The biggest obstacle to great software is lack of motivation. Motivate each other!
Instead of reinventing the wheel, we should put chariot wheels on jet planes!