L'obiettivo è quello di passare una matrice costante, (che rappresentano le variabili membro del parametro corrispondente struttura) come {{"network", "lan"}, {"dhcp", "true"}}
come parametro quando si chiama una funzione come:Come passare array letterale come argomento di input della funzione?
ubus_call("router", "client", {{"network", "lan"}, {"dhcp", "true"}}, 2);
Ho provato il seguente codice ma restituisce errori nel compilation:
struct ubus_args {
char *key;
char *val;
};
int ubus_call(char *obj, char *method, struct ubus_args u_args[], int size_args) {
printf("%s\n", obj);
printf("%s\n", method);
printf("%s %s\n", u_args->key, u_args->val);
return 0;
}
int main()
{
ubus_call("router", "client", {{"network", "lan"}, {"dhcp", "true"}}, 2);
return 0;
}
Come posso farlo nel modo giusto?
letterali composti, forse? –
"ma restituisce errori nella compilazione:" -> invia il messaggio di errore. – chux
Passaggio 1, usare 'int ubus_call (const char * obj, metodo const char *, const struct ubus_args * u_args, size_t size_args) ' – chux