I c, so you could pass a function many flags in any order using hexadecimal form and descriptive #define calls. And what would the syntax look like to parse the haxadecimal to determine which flags where set once in the body of the function?
If you're using C++, it's considered bad practice to use #define to declare constant values. That was something that was common 20 years ago, but people have learned that it's not a good idea (through many a trial and error - and I don't mean figuratively ).
Instead, people use 'const int'/'const unsigned' or enums to create permanently unchanging values. #defines have hidden dangers to them can cause bugs if they are overused (they aren't broken - they just sometimes behave in ways people don't expect resulting in obvious-in-hindsight but hard-to-locate bugs). Older books and tutorials, and older code libraries (like Win32) use alot of #defines.
C++ code doesn't need to know the difference between hexadecimal, decimal, octal, and binary. They are all just integers of some kind or another (maybe signed, maybe unsigned, depending on the context). C++ code itself doesn't care what human format we write our numbers in.
The compiler, when compiling our code, converts our C++ language code into machine assembly.
In the exact same way, the compiler converts our human numbering systems into whatever format (binary) the computer cares about.
Try running this code:
#include <iostream>
using namespace std;
void myFunc(int someValue)
{
std::cout << "Value: " << someValue << std::endl;
}
int main()
{
myFunc(255);
myFunc(0xFF);
myFunc(0377);
return 0;
}
There are two things to note here:
- The function didn't have to treat hexadecimal values any differently than 'normal' decimal values
- The output from the functions were exactly the same (because dec 255 == hex FF == oct 377; the values were equivalent)
The code didn't care at all. From our perspective, we wrote each number differently. From the code's perspective, it was the exact same thing.
These numbering systems can be used interchangeably for different purposes, whenever it is more convenient to write in one system over another.