sizeof() in function

Hello,
I want to write function which one of input will be an array. How should I declare it to check inside the function what is the size of this array?
I have something like that:

void sendFrame(unsigned int interval, byte* frame)
{
 
  for (int i = 0; i < sizeof(frame); i++)
  {
    Serial1.write(frame[i]);
    delayMicroseconds(interval);
  }
  Serial1.flush();
  delayMicroseconds(interval * 2);

and all the time I have sizeof(frame)=2. I change in declaring from byte* frame to byte frame[], but there the same effect.

How should I do declare array into this?

"sizeof()" isn't a function - it's a compile-time unary operator only.

So how should I solve this? I want to have, in function, length of frame which is my input without declaring next input (length of frame)?

Here is an article I've written on the topic: Passing arrays to functions

It shows how to do exactly what you ask.

I'm registered already on this website, but I have access denied :frowning: Could You send it to me some other way?

REACTIVE86:
I'm registered already on this website, but I have access denied :frowning: Could You send it to me some other way?

I have sent you a PM, however the site can generate dodgy pdf files, so you can read this for now.

FAQ-32-en.pdf (23.9 KB)

Could You send it to me some other way?

There is not another way. Somehow the called function needs to know the size of the array. Given ONLY its starting address, that is not, AT RUN TIME, possible for it to determine. You MUST pass the length or define a sentinel, similar to the NULL in a char array that defines the length of a string, that tells the function when to stop.

Defining a sentinel is not always possible. Passing the length is.

PaulS:
There is not another way. Somehow the called function needs to know the size of the array. Given ONLY its starting address, that is not, AT RUN TIME, possible for it to determine. You MUST pass the length or define a sentinel, similar to the NULL in a char array that defines the length of a string, that tells the function when to stop.

Defining a sentinel is not always possible. Passing the length is.

If you have an actual array, not just a block of memory, you'll have the size at compile time. The article I linked shows how to use either a reference or pointer to an array (not just to the first element) which preserves the size information.

pYro_65:
I have sent you a PM, however the site can generate dodgy pdf files, so you can read this for now.

Thanks a lot. It works now properly. I downloaded library ATL.h and use Template like on this pdf, which you've sent to me. Now everything working as I wanted. Big beer for you!

Now everything working as I wanted.

But, do you UNDERSTAND the code? Was it really simpler than passing the size of the array?

pYro_65:
I have sent you a PM, however the site can generate dodgy pdf files, so you can read this for now.

I didn't understand this part:

(adsbygoogle = window.adsbygoogle || []).push({});