This question already has an answer here:
- When a function has a specific-size array parameter, why is it replaced with a pointer? 3 answers
i know there are several threads asking a similar question but i couldn't find a solution and i'm somewhat new to c++.
I want to calculate the length of a DWORD array. So it's just an unsigned long.
DWORD offsets[] = {0x378, 0x14, 0x0};
This is my header definition of the func:
DWORD allocateAddress(DWORD, DWORD[]);
This is inside the cpp function:
DWORD Window::allocateAddress(DWORD baseAddress, DWORD offsets[])
{
DWORD buffer;
DWORD pointer;
int level = 3; // Length of offset array should be calculated here.
for (int c = 0; c < level; c++)
{
if (c == 0)
{
buffer = this->read(baseAddress);
}
pointer = buffer + offsets[c];
buffer = this->read(pointer);
}
return pointer;
}
This is how i would calculate the length:
sizeof(offset) / sizeof(*offset) // or sizeof(offset[0])
If i do it like this inside the allocateAddress function, i only get 4 bytes. Testing it in the main method returns 12 bytes, which is the value i want.
std::cout << sizeof(Address::offset) << std::endl;
Why am i getting the size of a 1 dimensional DWORD? =(