3

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?

zee
  • 2,933
  • 2
  • 16
  • 28

1 Answers1

4

You need a compound literal for this:

bar((struct foo){1});
dbush
  • 205,898
  • 23
  • 218
  • 273