W
William Pursell
I would like to initialize an array of structs,
one of whose members is an integer. Some of the
elements will get an explicit initializer for the
int, some will take the 0. The value is a monotonically
increasing counter, starting at 1. For example:
struct foo t[] = {
{ "apple", 1 },
{ "banana" },
{ "cherry", 2 },
{ "drape", 3 },
{ NULL }
};
I don't want to hard code the integer values, and
would rather do something like:
struct foo t[] = {
{ "apple", VALUE },
INCR( VALUE )
{ "banana" },
{ "cherry", VALUE },
INCR( VALUE )
{ "drape", VALUE },
{ NULL }
};
I can't see how to make the preprocessor do this
for me. Any ideas on how to accomplish this would
be greatly appreciated.
(For the curious, the structure I'm initializing
is a struct argp_option, and I'm trying to initialize
the group element to get things like --do-this
--no-do-this to be grouped together . Each time I add
an option to the option list, Everything below it
needs to have the value changed. This is easy enough,
but seems unecessary.)
one of whose members is an integer. Some of the
elements will get an explicit initializer for the
int, some will take the 0. The value is a monotonically
increasing counter, starting at 1. For example:
struct foo t[] = {
{ "apple", 1 },
{ "banana" },
{ "cherry", 2 },
{ "drape", 3 },
{ NULL }
};
I don't want to hard code the integer values, and
would rather do something like:
struct foo t[] = {
{ "apple", VALUE },
INCR( VALUE )
{ "banana" },
{ "cherry", VALUE },
INCR( VALUE )
{ "drape", VALUE },
{ NULL }
};
I can't see how to make the preprocessor do this
for me. Any ideas on how to accomplish this would
be greatly appreciated.
(For the curious, the structure I'm initializing
is a struct argp_option, and I'm trying to initialize
the group element to get things like --do-this
--no-do-this to be grouped together . Each time I add
an option to the option list, Everything below it
needs to have the value changed. This is easy enough,
but seems unecessary.)