Skip to main content
gamedev.net
🔒 Locked

Syntax HELP

Started by julienX 1 reply 150+ views
Original Post
julienX
julienX
Ok ill give an example to start with: MessageBox(NULL,"This is weird","Hello", MB_OK | MB_ICONINFORMATION); Why is only one | used? I''ve been taught in my book that to use the OR statement you would do it like this: if (choice1 || choice2) But in windows its all different, its always used once: only 1 | and only one &. Please, any advice would UNCONFUSE me! Oh yeah, also why do you have to use the | to add multiple flags in windows? Wouldn''t you use & to say ''MB_OK AND MB_ICONINFORMATION, not ''MB_OK OR MB_ICONINFORMATION??
chacha
Miserable
Miserable
It is because | and || are entirely different operators (as are & and &&). || is a logical OR. | is a bitwise OR, used to combine the bits in two memory locations. Applied thus it works as expected: When at least once source bit is set, the destination bit will be set; if neither source bit is set, nor will be the target. (Bitwise AND works in an analogous fashion.)


0100 1101
| 1001 1100
-----------
1101 1101

Knowing this, the reason why you use the bitwise OR to combine bit flags should be fairly clear (it''s the only way to conveniently access individual bits).
julienX
julienX
Thanks a lot, I understand now
chacha

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.