I'm curious if there's a better way of changing every variable in a structure instead of the following block of code.
struct RuntimeData
{
double runtime_ms, sum_ms, avg_time_ms, best_time_ms;
};
int main()
{
struct RuntimeData selection;
// The '0' values are just for example..
selection.runtime_ms = 0;
selection.sum_ms = 0;
selection.avg_time_ms = 0;
selection.best_time_ms = 0;
}
I'd much rather be able to do something similar to this...
struct RuntimeData selection;
selection = { .runtime_ms=0,
.sum_ms = 0,
.avg_time_ms = 0,
.best_time_ms = 0
};
...or something similar. I know you can do the latter codeblock while initializing the structure, but it results in a compilation error after the struct has already been initialized.
EDIT: Using Nate's and Vlad's answers, a compound literal is exactly what I needed! Thank you so much.