Reputation: 654
I'm trying to define the following macro functions:
#define TEST_INSTRUCTIONS_INPUT(name) const InstructionArray name =
#define TEST_INSTRUCTIONS_SIZE(name) const uint16_t name_size = sizeof(name) / sizeof(name[0]);
The first works, but the second does not (name
is not replaced).
In general it seems F(x) x_name
will not replace x
, so F(test)
-> x_name
, rather than test_name
My guess is the C preprocessor:
_
as a valid delimeter between 'words'Is there a way around this to get what I want? (Function declerations with "decorated" names).
Thanks.
Upvotes: 0
Views: 207
Reputation: 141493
Is there a way around this to get what I want?
Yes, concatenate the tokens. This is what ##
is for.
#define TEST_INSTRUCTIONS_SIZE(name) const uint16_t name##_size = ...
Upvotes: 1