4 ms·
That's how it works already, eg: #include <stdio.h> #include <stdlib.h> struct params { int a; void *p; }; void f (struct params p) {
by rwmj 4y ago
That's how it works already, eg:
#include <stdio.h>
#include <stdlib.h>
struct params {
int a;
void *p;
};
void
f (struct params p)
{
printf ("p.a = %d, p.p = %p\n", p.a, p.p);
}
int
main (void)
{
f ((struct params){.a = 42});
f ((struct params){.p = f});
f ((struct params){});
exit (EXIT_SUCCESS);
}
Even though these are stack allocated, the missing fields are initialized to 0/NULL. The last case (no parameters) is new in C23. In C99 you had to use (struct params){0} to initialize it. https://en.cppreference.com/w/c/language/compound_literal https://en.cppreference.com/w/c/language/compound_literal