Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Okay, I didn't mean to answer my own question here, but I've come up with a decent solution that is somewhat of a combination of Mark Wilkins answer and the example I gave in the question.</p> <p>It is possible to stringify the entire set variadic set, which then includes the delimiting commas in the string. Here's a quick example:</p> <pre><code>#define MY_VARIADIC_MACRO(X...) printf(#X) </code></pre> <p>Using the above macro shows you that the entire set of arguments passed to the macro gets stringified.</p> <p>Then you can then define a function to tokenize these arguments using the delimiting comma, thereby getting the set of tokenized strings by using the variadic macro:</p> <pre><code>#define MY_VARIADIC_MACRO(X...) tokenize_my_arguments(#X) </code></pre> <p>Then there's actually no longer the dependency of having the variadic macro call a variadic function and I can iterate nicely through my array of constant C strings rather than iterating through va_arg.</p> <p><em><strong></em>* New Stuff from Edit Follows <em>*</em></strong></p> <p>Per Tim's comment, here's the details of the solution. Please forgive any errors since it was done in haste and I had to port from what I'm working on. Also, it's not meant to be copy/paste solution since it only outputs the stringification of the arguments to demonstrate POC, but should be sufficient enough to demonstrate the functionality.</p> <p>Although this solution requires some run time computation, variadic macros often times call variadic functions and requires iterating through va_args, so the iteration takes place in finding the tokens, although a bit of performance is probably sacrificed. However, for maintainability, versatility, and ease of implementation, this seems to be the best option at the moment:</p> <pre><code>#define VARIADIC_STRINGIFY(_ARGUMENTS_TO_STRINGIFY...) Variadic_Stringification_Without_Variadic_Function(#_ARGUMENTS_TO_STRINGIFY) void Variadic_Stringification_Without_Variadic_Function (const char* _stringified_arguments) { strcpy(converted_arguments, _stringified_arguments); for(char* token = strtok(converted_arguments, ","); token != 0x0; token = strtok(0x0, ",")) std::cout &lt;&lt; token &lt;&lt; std::endl; } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload