I was trying to create and initialize a struct using a variable length macro. I want to be able create/initialize the struct with '0's and then initialize some fields of the struct with values that were optionally passed in.
Is this possible to do? I was trying the following:
#define INIT_ENTRY(x, ...) \
entry_t x = {.id = 0, .age = 0} \
x.id = <I want to use arg1 here>
x.age = <i want to use arg2 here if it exists>
Is there a way to accomplish this?
x = INIT_ENTRY(x, 1)would do about(entry_t){.id = 1}andx = INIT_ENTRY(x, 1, 2)would do about(entry_t){.id = 1, .age = 2}? What is the max length needed - arbitrary? BTW:x.id = <I want to use arg1 here>is not initialization, but assignment.