Working with some tutorial, I met a strange C++ expression:
uint64_t var = ....
return (*&var) - 1.f;
What does this mean? Is it a reference to a pointer? What's the point of substracting 1 from reference? It should be an implementation of the LCG algorithm.
varis an identifier. It names a variable.The unary
&operator is the addressof operator. The result of addressof operator is a pointer to the object named by its operand.&varis a pointer to the variablevar.The unary
*operator is the indirection operator. Given a pointer operand, it indirects through that pointer and the result is an lvalue to the pointed object. It is an inverse of the addressof operator.When you get the address to an object, and then indirect through that pointer, the resulting value is the object whose address you had taken. Essentially, in this case
*&varis an unnecessarily complicated way to writevar.In this case, the referred value is an integer. The point of subtracting 1.f from an integer is to get a smaller value of floating point type.