Taata
Taata

Reputation: 117

How to pass array's size as another argument with sizeof

I have the function below :

addToTxBuffer((uint8_t []){0x01,0x11}, 2, zeroPad);

The second argument 2 is the size of first argument. I would like to use sizeof instead of 2. Is there any syntax that makes it possible? i.e. :

addToTxBuffer((uint8_t header[]){0x01,0x11}, sizeof(header), zeroPad);

this does not work though.

Upvotes: 1

Views: 79

Answers (1)

dbush
dbush

Reputation: 223872

Compound literals are unnamed, so you can't reference them in that way. You would need to define the array separately, then you can get its size:

uint8_t header[] = {0x01,0x11};
addToTxBuffer(header, sizeof(header), zeroPad);

Upvotes: 6

Related Questions