By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,820 Members | 1,187 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,820 IT Pros & Developers. It's quick & easy.

Using macros with variable arguments for static initialization.

P: n/a
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?


Nov 3 '06 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.