Could anybody help me to understand what the | OR bitwise operator doing in this function?
Here's the whole program btw.Code:SetConsoleTextAttribute ( h, BACKGROUND_RED | 8 );
http://cboard.cprogramming.com/showthread.php?t=110879
Could anybody help me to understand what the | OR bitwise operator doing in this function?
Here's the whole program btw.Code:SetConsoleTextAttribute ( h, BACKGROUND_RED | 8 );
http://cboard.cprogramming.com/showthread.php?t=110879
Using Windows 10 with Code Blocks and MingW.
What is it that you do not understand about it?
--
Mats
Compilers can produce warnings - make the compiler programmers happy: Use them!
Please don't PM me for help - and no, I don't do help over instant messengers.
It would be better to go read the manual to find out what 8 really means (bold, flash, whatever), and use the appropriately named readable constant.
Not some magic number pulled out of the ether.
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.
You mean such as:
FOREGROUND_INTENSITY
--
Mats
Compilers can produce warnings - make the compiler programmers happy: Use them!
Please don't PM me for help - and no, I don't do help over instant messengers.
Well i already checked out the manual but it says nothing about numbers or bitwise operator.
And what is it that a color has to do with a bitwise operator?
http://msdn.microsoft.com/en-us/libr...47(VS.85).aspx
Using Windows 10 with Code Blocks and MingW.
From the link, once you click on "character attributes":
The character attribute variable is just a bunch of flags, and each of these named constants is just a bitmask, so you can set whichever flags you want to set by ORing them together.The foreground attributes specify the text color. The background attributes specify the color used to fill the cell's background. The other attributes are used with DBCS.
An application can combine the foreground and background constants to achieve different colors. For example, the following combination results in bright cyan text on a blue background.
FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_INTENSITY | BACKGROUND_BLUE
If no background constant is specified, the background is black, and if no foreground constant is specified, the text is black. For example, the following combination produces black text on a white background.
BACKGROUND_BLUE | BACKGROUND_GREEN | BACKGROUND_RED
Im really lame. Im gonna pay more attention next time. Thank you Tabstop!
But what about the number 8, what does it mean?
Using Windows 10 with Code Blocks and MingW.
8 is one of those named constants. If I wanted to know which one, I'd look in the corresponding header file and see which of them is defined to be 8.
My guess is that it's the foreground intensity bit [based on guess-and-vague-memory principle] that I posted about earlier, but if you have Visual Studio or some other editor that allows you to "go to definition" of that name, then go to the definition of the background colour, and the all declaration of the foreground and background colours are (I would expect) nearby, so just find which one has the value 8.
--
Mats
Compilers can produce warnings - make the compiler programmers happy: Use them!
Please don't PM me for help - and no, I don't do help over instant messengers.
As stated by matsp:
From: http://doc.ddart.net/msdn/header/include/wincon.h.htmlCode:#define FOREGROUND_INTENSITY 0x0008 // text color is intensified.
"Owners of dogs will have noticed that, if you provide them with food and water and shelter and affection, they will think you are god. Whereas owners of cats are compelled to realize that, if you provide them with food and water and shelter and affection, they draw the conclusion that they are gods."
-Christopher Hitchens
You probably just shouldn't be using 8 in this context. But if you have 8, you can try to find the windows header where all these BACKGROUND_BLUE's and such are defined and see which of these is defined as 8.
In "wincon.h" you'll find the following:
Code:#define FOREGROUND_BLUE 1 #define FOREGROUND_GREEN 2 #define FOREGROUND_RED 4 #define FOREGROUND_INTENSITY 8 #define BACKGROUND_BLUE 16 #define BACKGROUND_GREEN 32 #define BACKGROUND_RED 64 #define BACKGROUND_INTENSITY 128
I might be wrong.
Quoted more than 1000 times (I hope).Thank you, anon. You sure know how to recognize different types of trees from quite a long way away.
Thank you, anon. You sure know how to recognize different types of trees from quite a long way away.
Wow that was simple! Now either these kind of things arent in the tutorials or i must have missed them somehow.
Anyways, thanks a lot everybody!
Last edited by Ducky; 02-26-2009 at 10:50 PM.
Using Windows 10 with Code Blocks and MingW.
Also notice that all the constants are powers of two (in binary these are numbers which have one bit set - each value a different bit). This is what allows them to be combined using bitwise or (in case you want to do something like this yourself)
I might be wrong.
Quoted more than 1000 times (I hope).Thank you, anon. You sure know how to recognize different types of trees from quite a long way away.