|
BDE 4.14.0 Production release
|
Macros | |
| #define | BSLS_UTIL_ADDRESSOF(OBJ) (&(OBJ)) |
Provide essential, low-level support for portable generic code.
OBJ, even if operator& overloadedThis component defines a utility struct, bsls::Util, that serves as a namespace for a suite of pure functions that supply essential low-level support for implementing portable generic facilities such as might be found in the C++ standard library.
This section illustrates intended use of this component.
There are times, especially within low-level library functions, where it is necessary to obtain the address of an object even if that object's class overloads operator& to return something other than the object's address.
First, we create a special reference-like type that can refer to a single bit within a byte (inline implementations are provided in class scope for ease of exposition):
Then, we create a pointer-like type that can point to a single bit:
Next, we overload operator& for BitReference to return a BitPointer instead of a raw pointer, completing the setup:
Then, we note that there are times when it might be desirable to get the true address of a BitReference. Since the above overload prevents the obvious syntax from working, we use bsls::Util::addressOf to accomplish this task.
Next, we create a BitReference object:
Now, we invoke bsls::Util::addressOf to obtain and save the address of br:
Notice that the commented line illustrates canonical use of operator& that would not compile in this example.
Finally, we verify that address obtained is the correct one, running some sanity checks:
| #define BSLS_UTIL_ADDRESSOF | ( | OBJ | ) | (&(OBJ)) |