This is because C/C++ does not save the length of an array anywhere in memory.
The "offsets" parameter is declared as an array of undefined length. this is of course correct since you want to support any array, BUT this means that there is no way to know the size of the array at runtime.
Think of it this way: the "sizeof" keyword returns a result based on the declaration of the variable ONLY and not the actual size at runtime.
If your variable is delcared this way:
DWORD offsets[3]
Then its type is an "array of 3 DWORDs" (DWORD[3]
), so sizeof will return the size in bytes of a "array of 3 DWORDs" or 12 bytes. In your case, the size of the array is implicitly defined as DWORD[3]
because you initialize it with three values.
But if you declare a parameter as:
DWORD offsets[]
Its type becomes an "array of unknown length" (or DWORD[]
). Since this is functionnaly identical to a constant pointer, "sizeof" will acts as if there is one element. So "sizeof" returns 1 * sizeof(DWORD) = 4.