take this ungodly bit of code that I just wrote. I'm not sure how we can agree that a reference is basically a dereferenced pointer and still come to the end of the conversation and still be at odds in some points.
1 2 3 4 5 6 7 8
|
for (auto i = bd.pptr; i < (bd.pptr + size); i++) {
if (i && *i && **i) {
int* type_ptr = &(**i);
type = *(type_ptr + 3);
break;
}
}
|
as i mentioned earlier the reasons why this is necessary is bc the int* 's in the int** aren't sequential. and their addresses aren't the same as where the actual data is stored. they just hold the value of the address where the data is stored.
the above works and needs to be that way bc I don't actually need the data stored at **i, I need the actual address, bc I want the data at the address 3 houses down.
The reason why my pov changed slightly is bc I'm actually looking directly at the memory itself bc I honestly have no other choice. Look at it for yourself.
Reference by deffinition is just 2 objects that are the same. you change one and the other changes bc they're the same thing. The underlying compiled code makes no distinction between a pointer and a reference bc there is no difference it just sends the resulting address and the bytes are moved into the registers etc.
Think about it this way. there can only be one thing in a memory address. So that being said a value that a variable holds can't be held and still know its own address...So if you have an int a=4; that 4 gets stored somewhere but it lives somewhere else than where a lives.
in memory address 1234[ 4 ], somewhere else address 4321[1234] is representative of int a;
So if you want to get uber detailed &a == 1234 a == 4
int* x = &a; x value address = abcd[4321]
&x would be bbbb [abcd]
theres an extra layer in there that none thinks about. I never thought about it either.
the key point being a particular memory address can't save more than one thing and you have 2 things... the variable itself and the value it holds.
doing something like int a = 4;
int& b = a;
the reason b can be a reference to a and still be its own thing is because of something like
1234[4] <~~~4 address
a == 4321[1234] a address and value
b == 3333[1234] ....
to clarify i'm using values in the square brackets bc again that address can only hold one thing it can't hold 1234 things etc.
now dont' get me wrong the address of a variable is just a temporary reference and if its not needed could deffinetly be removed by the compiler but that's just a whole other discussion.
in the situation i'm dealing with theres no optimizations to interpreting a script (at least not in the language so those temp references are all there. not very temporary.