Using macros with variable arguments for static initialization.

  • Thread starter Max TenEyck Woodbury
  • Start date
M

Max TenEyck Woodbury

I have a static array that requires quite complicated initialization.
With C89 I constructed a set of macros that greatly simplified that
process but required the user to count the number of arguments. With
the advent of C99, I can get around that problem. However I wish to
hide even more of the implementation details being yet another macro.
The macro would have a form something like SUPER_TABLE( name, (...)...)
where the (...) arguments would be processed by the macro I described
above. The problem is the mechanism behind SUPER_TABLE.

The macro would do what was needed with 'name', check to see if there
is more than one additional argument in the argument list, (how this
can be done was discussed quite some time ago in this news group) and
invoke SUPER_TABLE0 if here was only one, or SUPER_TABLE1 if there
as more than one. SUPER_TABLE0 is what I already have. SUPER_TABLE1
would split off one argument set and pass it to SUPER_TABLE0, then
pass the rest of the arguments to another incarnation of itself.
The termination of the initialization would be in SUPER_TABLE.

The problem is how to get around the preprocessor's recursion
prevention. Recursion is safe in this case because it is limited
to one level per argument. However the number of arguments could
be arbitrarily large so counting the arguments is not a solution.

Could somebody tell me how to do this?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,902
Latest member
Elena68X5

Latest Threads

Top