Search code examples
cfunctionargumentsparameter-passingdefinition

Is there a way to define an array by an argument to a function call?


I've got a function which expects a variable and a pointer.

void sendCMD(byte cmd, byte data[]){
    ...
}

Is it possible to call this function with the data in anyway like so

sendCMD(0xff, { 0x0a, 0x02 });

Since even by googleing I didn't find anything... maybe I haven't looked hard enough, but I'm also not exactly sure what the terms are I should be looking for. Any help is kindly appreciated! Note that byte is the same thing as a char!


Solution

  • You can use a compound array literal:

    sendCMD(0xff, (byte[]){ 0x0a, 0x02 });