Handmade Hero»Forums»Code
2 posts
Win32ProcessPendingMessages comparing uint32 with const char *
Edited by judgebread on 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?
Alex Baines
44 posts / 2 projects
Win32ProcessPendingMessages comparing uint32 with const char *
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?
2 posts
Win32ProcessPendingMessages comparing uint32 with const char *
Yup. I was using double quotes. Didn't know single and double quotes mean different things in C++. Thanks for clarifying!
Mikael Johansson
99 posts / 1 project
Win32ProcessPendingMessages comparing uint32 with const char *
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.