I am gradually porting and refactoring C code to C++.
In the original C code, I have constructs like this:
Object* obj = &objects[index]
where objects
is a global Object[]
.
I refactored the code so the array is dynamically allocated and a different object holds the array:
struct Info {
Object* objects;
}
Due to my gradual refactoring, I wrote the following free function:
Object* GetObjects(Info* i) {
return i->objects;
}
Now my question is:
Does the following code behave like I would expect (getting the address of an object in the array)?:
Object* obj = &GetObjects(info)[index];
Am I getting the Address of an object in the array (what I want) here or the address of the array or some rvalue and invoke UB?
[]
has higher precedence than &
but does that also count for function calls?