Array in C always passed by reference. Thats why you are getting pointer size each time, not actual size.
To work with array in C as an argument, you should pass size of array with array.
I modified your program to working condition:
typedef unsigned char BYTE;
void checkArraySize(BYTE data[], int sizeOfArray)
{
int internalSize = sizeOfArray;
printf("%d", internalSize );
}
void main(void)
{
BYTE data[] = {0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08};
int externalSize = sizeof(data)/sizeof(BYTE); //it would return number of elements in array
checkArraySize(data, externalSize);
}
passed by reference means only address of first element of array is sent. If you change anything even inside function checkArraySize, this change would be reflected to original array too. Check modified above example.
typedef unsigned char BYTE;
void checkArraySize(BYTE data[])
{
int internalSize = sizeof(data);
printf("%d\n", internalSize );
data[3]= 0x02; //internalSize is reported as 4
}
void main(void)
{
BYTE data[] = {0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08};
int externalSize = sizeof(data); //externalSize is reported as 8
printf("Value before calling function: 0x%x\n",data[3]);
checkArraySize(data);
printf("Value after calling function: 0x%x\n",data[3]);
}
output would be:
Value before calling function: 0x4
4
Value after calling function: 0x2