Today at work we came across the following code (some of you might recognize it):
#define GET_VAL( val, type ) \ { \ ASSERT( ( pIP + sizeof(type) ) <= pMethodEnd ); \ val = ( *((type *&)(pIP))++ ); \ }
Basically we have a byte array and a pointer. The macro returns a reference to a variable of type and advance the pointer to the end of that variable.
It reminded me of the several times that I needed to ‘think like a parser’ in order to understand C++ code.
Do you know of other code examples that caused you to stop and read it several times till you managed to grasp what it was suppose to do?
The inverse square root implementation in Quake 3:
Update: How this works (thanks ryan_s)