Sizeof reduced to 4 once on a function

Hello,

I have a known frame that I'm sending to a function which is making me crazy because the size of the frame when received on this function is 4, so I'm loosing a lot of data.
I'm using an ESP8266 board.

Here is my code :

void setup() {
  Serial.begin(300);
}

void loop() {
  uint8_t Frame[] = {0x23, 0x10, 0xE0, 0xA2, 0x11, 0x68, 0x32, 0xC2};
  Serial.println(sizeof(Frame));
  CountFrameSize(Frame);
}

void CountFrameSize(uint8_t frame[]) {
  Serial.println(sizeof(frame));
}

And what is displayed on the serial

8
4

Do you know why the sizeof have reduce to 4 ? And how to keep correct length ?
I have tried whith shorter and longer frame length, and it's always 4.

Honestly, if you would have fired up Google you would have found your answer way quicker. But to recap, sizeof() is done at compiler time. So in the function it returns the size of the local 'frame' (function argument), not the size of what you pass to that function. And because 'frame' is defined as "uint8_t frame[]" = "uint8_t* frame" aka it's a pointer which is 4 bytes on an ESP.

Solution, or work on the global variable (but then you would not be able to pass different variables) or pass the size to the function as well.

Thanks septillion.
I knew this subtlety but didn't notice the impact that could have here, thanks to your explanation I understand it.
Adding the size to the function parameter works well.

@OP

Will you please, post your codes to allow me seeing how the problem is solved?

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.