Wondering through the LLVM source code i stumbled upon this line of code
MachineInstr *MI = &*I;
I am kinda newb in c++ and the difference between references and pointers is quite obscure to me, and I think that it has something to do about this difference, but this operation makes no sense to me. Does anybody have an explanation for doing that?
The type of I
is probably some sort of iterator or smart pointer which has the unary operator*()
overloaded to yield a MachineInstr&
. If you want to get a built-in pointer to the object referenced by I
you get a reference to the object using *I
and then you take the address of this reference, using &*I
.
C++ allows overloading of the dereference operator, so it is using the overloaded method on the object, and then it is taking the address of the result and putting it into the pointer.
This statement:
MachineInstr *MI = &*I;
Dereferences I
with *
, and gets the address of its result with &
then assigns it to MI
which is a pointer to MachineInstr
. It looks like I
is an iterator, so *I
is the value stored in a container since iterators define the *
operator to return the item at iteration point. The container (e.g. a list) must be containing a MachineInstr
. This might be a std::list<MachineInstr>
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With