0

There is a macro that I want to use that takes arguments in this format:

COMB(unique identifier, argument 1, argument 2, argument 3)

I want to create a wrapper for it that automatically generates the unique identifier. I found this answer that has code to generate a random ID, which I am using in my code:

#define PP_CAT(a, b) PP_CAT_I(a, b)
#define PP_CAT_I(a, b) PP_CAT_II(~, a ## b)
#define PP_CAT_II(p, res) res

#define UNIQUE_NAME(base) PP_CAT(base, __COUNTER__)

#define COMB_U(key, ...) COMB(UNIQUE_NAME(comb_r_), key, __VA_ARGS__)

// Using the macro
// The parameters are enums
COMB_U(KB_1, KB_2, KC_Y)

When I compile this I get a bunch of errors from inside of the COMB macro code like this:

‘cmb_UNIQUE_NAME’ declared as function returning an array

function ‘cmb_UNIQUE_NAME’ is initialized like a variable

As well as inside of the file with my code:

‘comb_r_’ undeclared here (not in a function)

#define COMB_U(key, ...) COMB(UNIQUE_NAME(comb_r_), key, VA_ARGS)

And a bunch of messages that don't seem to be associated with an error, like this one:

note: in expansion of macro ‘COMB_U’

COMB_U(KB_1, KB_2, KC_Y)

How can I fix this?

For reference, the source for the COMB macro is here: https://github.com/germ/qmk_firmware/blob/master/keyboards/gboards/g/keymap_combo.h

Merlin04
  • 1,837
  • 4
  • 23
  • 27
  • I believe [this](https://stackoverflow.com/a/28327732/10142251) should answer your question. – Pranjalya Sep 08 '20 at 03:43
  • That question is about generating a name for a macro, but I'm trying to generate a parameter that will be passed to a macro. – Merlin04 Sep 09 '20 at 14:50

0 Answers0