pr****@googlemail.com wrote:
Hi,
I write the following code:
void someproc() {
int controlids [] = {
IDC_BUTTON_RC_CONNECT,
IDC_BUTTON_RC_CONNECTPUBLIC,
IDC_BTN_SENDHELLO };
someproc2(controlids);
}
void someproc2(int * e)
{
int size = sizeof(e)/sizeof(int);
//.. do something with size.. like use in a for loop etc...
}
I expected to get the correct size, but it just gives me 1. What am I
doing wrong?
Your expectations were met: you got the correct size.
Note the signature: void someproc2(int * e ). You say that e is a variable
of type int*. Well, the size of a pointer to int on your machine just
happens to be the same as the size of an int. Note that the size of an int*
says nothing about the length of the array to whose first element that
pointer is pointing.
Best
Kai-Uwe Bux
ps.: If you want to keep track of the length of an array, consider using
std::vector.