sending args via or ( | )
hi
i noticed that in some functions, such as some in the windows.h,
u can send parameters with or ex...
func( 5 | 7 | 8, g | j);
how do i write a function to handle this?
i know how to write a function to receive elipses using stdarg.h, is this similar?\
thanks!
No, they are different methods. You can look up the usage of the "..." parameter under va_start, va_end, and va_arg.
The "|" means OR; it combines bits in either variable (or in many cases, constants/macros). If either one''s bit is true, then the end result is true. You can use it like this (this is an example, there''s many more ways to use it, and this example isn''t really practical):
![Resist Windows XP''s Invasive Production Activation Technology!](http://druidgames.warfactory.com/Out_Source/resist.jpg)
http://druidgames.cjb.net/
The "|" means OR; it combines bits in either variable (or in many cases, constants/macros). If either one''s bit is true, then the end result is true. You can use it like this (this is an example, there''s many more ways to use it, and this example isn''t really practical):
|
![Resist Windows XP''s Invasive Production Activation Technology!](http://druidgames.warfactory.com/Out_Source/resist.jpg)
http://druidgames.cjb.net/
The bitwise | operator is evaluated before being passed as in as an argument. All expressions are evaluated first.
Your example above takes two arguments. So, write a function that takes two arguments.
Your example above takes two arguments. So, write a function that takes two arguments.
_______________________________
"To understand the horse you'll find that you're going to be working on yourself. The horse will give you the answers and he will question you to see if you are sure or not."
- Ray Hunt, in Think Harmony With Horses
ALU - SHRDLU - WORDNET - CYC - SWALE - AM - CD - J.M. - K.S. | CAA - BCHA - AQHA - APHA - R.H. - T.D. | 395 - SPS - GORDIE - SCMA - R.M. - G.R. - V.C. - C.F.
"To understand the horse you'll find that you're going to be working on yourself. The horse will give you the answers and he will question you to see if you are sure or not."
- Ray Hunt, in Think Harmony With Horses
ALU - SHRDLU - WORDNET - CYC - SWALE - AM - CD - J.M. - K.S. | CAA - BCHA - AQHA - APHA - R.H. - T.D. | 395 - SPS - GORDIE - SCMA - R.M. - G.R. - V.C. - C.F.
EvilCrap: This can be done, but it only works in certain cases. The example you gave, 5 | 6 | 7, is not going to work. If you combine those three values with a bitwise OR, you won''t be able to recover them. Combining flags with a bitwise OR works when no two of the flags ever have the same bit set to 1. If this condition is met, then you can extract flags by using a bitwise AND. For defining these flags, powers of 2 are usually used, because a power of 2 has only one of its bits set to 1. Thus, when using a 32-bit integer, you can use bitwise OR to combine up to 32 flags such that they can all be read back again. For example:
#define SAMPLEFLAGA 1
#define SAMPLEFLAGB 2
#define SAMPLEFLAGC 4
#define SAMPLEFLAGD 8
#define SAMPLEFLAGE 16
and so on. Then you could call a function requiring a series of flags by combining all the required flags into a single argument, like this:
foo(SAMPLEFLAGA | SAMPLEFLAGC | SAMPLEFLAGD);
Now inside the body of the function, if dwFlags is the name of the parameter for the function, and you want to check if one of the flags is set, you''d do something like this:
if (dwFlags & SAMPLEFLAGC)
{
// code to execute if flag C is set goes here
}
Sorry this is kind of a fast explanation, but hopefully it makes sense.
-Ironblayde
Aeon Software
"In C we had to code our own bugs. In C++ we can inherit them." - Unknown
#define SAMPLEFLAGA 1
#define SAMPLEFLAGB 2
#define SAMPLEFLAGC 4
#define SAMPLEFLAGD 8
#define SAMPLEFLAGE 16
and so on. Then you could call a function requiring a series of flags by combining all the required flags into a single argument, like this:
foo(SAMPLEFLAGA | SAMPLEFLAGC | SAMPLEFLAGD);
Now inside the body of the function, if dwFlags is the name of the parameter for the function, and you want to check if one of the flags is set, you''d do something like this:
if (dwFlags & SAMPLEFLAGC)
{
// code to execute if flag C is set goes here
}
Sorry this is kind of a fast explanation, but hopefully it makes sense.
-Ironblayde
Aeon Software
"In C we had to code our own bugs. In C++ we can inherit them." - Unknown
"Your superior intellect is no match for our puny weapons!"
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement