1

Lets say I have some #defines

#define _TEST_FOO()  // some code here
#define _TEST_BAR()  // some code here

#define ABC FOO
#define BCD BAR

Can I create another #define like so:

#define CONCATENATE(x)   //??something here??

Where if somewhere in code I would useCONCATENATE(ABC); or CONCATENATE(BCD); it would generate _TEST_FOO(); and _TEST_BAR(); respectively.

Thanks

EDIT:

Sorry for the mistake, I meant:

#define _TEST_FOO_CLK_ENABLE()
#define _TEST_BAR_CLK_ENABLE()

So the result when calling CONCATENATE(x); should be:

_TEST_FOO_CLK_ENABLE();
_TEST_BAR_CLK_ENABLE();
user1806687
  • 934
  • 1
  • 10
  • 27

1 Answers1

3

This should be possible with one extra round of expansion:

#define CONCATENATE(x) CONCATENATE2(x)
#define CONCATENATE2(x) _TEST_ ## x ## _CLK_ENABLE ()

[Live example]

The extra indirection is necessary to force the argument itself (e.g. ABC) to be expanded. Without it, we'd end up with _TEST_ABC().

Angew is no longer proud of SO
  • 167,307
  • 17
  • 350
  • 455
  • @user1806687 Are there any more edits you are going to do to the question? I am not updating the answer to hit a moving target. Please tag me when the question is in its final form so I can address it (and please *please*, in the future, try to get the question right the first time). – Angew is no longer proud of SO Jun 14 '19 at 13:18
  • @user1806687 OK, edited. – Angew is no longer proud of SO Jun 14 '19 at 13:32
  • I will accept your anwser as it was the solution for the problem as I asked. But it did not work with my case, I ommited a lot of information. If you want to have another go at it, new question is posted at: https://stackoverflow.com/questions/56600682/how-to-force-macro-to-not-expand – user1806687 Jun 14 '19 at 14:57