To create a struct I can do one of the following:
// Method 1
Item *item = malloc(sizeof(Item));
Item _item = {.name="job"};
item = &_item;
// Method 2
Item *item = malloc(sizeof(Item));
item->name="job";
Is there a simpler method to do this? Perhaps something along the lines of:
malloc(sizeof(Item)) & (Item) {.name="job"}
Here are the two methods: https://godbolt.org/z/MfYGW3
question from:https://stackoverflow.com/questions/65945828/initializing-a-struct-with-malloc