Am 11.04.16 um 07:17 schrieb Robbie Hatley:
>
> On 4/8/2016 4:24 AM, Christian Gollwitzer wrote:
>
>> is it possible to stringify a list of arguments in a preprocessor macro?
>>
>> Background: I'm interfacing with a C library, which expects two
>> parallel arrays, one with C strings, one with function pointers.
>> I'd like to be able to pass only a the list of functions to the macro.
>> So I'd like to have
>>
>> TABLE(add, subtract, multiply)
>>
>> generate this code
>>
>> const char * text[] = { "add", "subtract", "multiply", NULL };
>> void * fun[] = { add, subtract, multiply };
>
> Easy as pie.
>
> Save the following to file called "table-macro-test.cpp":
>
> #define TABLE(X,Y,Z) \
> const char * text[] = { #X, #Y, #Z, NULL }; \
> void * fun[] = { add, subtract, multiply };
>
> TABLE ( add , subtract , multiply )
Thanks for your answer. This works for exactly three arguments. I want
to use the macro several times with a varying number of arguments. The
rest of the macro is also larger and generates a function. Fortunately,
I found a solution:
This macro:
https://github.com/swansontec/map-macro
can perform a maplike operation over a list of up to 360 arguments.
I needed to enhance it to pass an extra argument to the "lambda"-macro,
which turned out to be easy:
https://github.com/auriocus/AsynCA/blob/master/generic/map.h
Best regards,
Christian