I want to be able to pass a variable number of objects in C to a function, by wrapping it in an array. As an example:
void test(int arr[]) {}
int main (int argc, char** argv) {
test({1, 2});
}
But I'm not certain how to go about creating an in-line array, and googling the problem leads to a lot of unrelated results.
I've also tried these variations:
test(int[]{1, 2});
test(int[2]{1, 2});
However have not found any reasonable way to create this. How is this possible in C?
As a note, I cannot use varargs.
Edit:
The code used and the compiler error:
void test(int ex[]) {}
int main() {
test(int[]{1, 2});
}
test.c:4:10: error: expected expression before 'int'