In C++ this code is valid
struct foo{
int x;
};
int bar(foo f);
bar({1});
However I get an error when I try to do something similar in C. Is there way a to pass a struct to a function without actually creating a variable for it?
You need a compound literal for this:
bar((struct foo){1});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With