0

I would like to know is there any way to achieve this.

My requirement is to make the macro argument to be part of sub macro names for example:

I have

#if defined DEBUG_1
#define DEBUG_PRINT_1(fmt,args...) printf(fmt, ##args)

#if defined DEBUG_2
#define DEBUG_PRINT_2(fmt,args...) printf(fmt, ##args)

I want to combine these macro to be a configurable one as follows

#if defined DEBUG_x
#define DEBUG_PRINT_x(fmt,args...) printf(fmt, ##args)

How would I place this x in the second statement?

Let me know if this is possible or not and suggest other ways to achieve this printing verbosity with a single macro definition than multiple definitions

runner
  • 591
  • 2
  • 7
  • 20
  • How would you *define* these then? – Eugene Sh. Oct 20 '20 at 19:25
  • `#if defined DEBUG(1)` doesn't compile for me. How about having a single macro `DEBUG_PRINT(number, fmt, args...)` that checks if `DEBUG_##number` is defined? (Refer to the second part of [this](https://stackoverflow.com/a/55243651/2752075) answer.) – HolyBlackCat Oct 20 '20 at 19:36
  • #if defined DEBUG(1) this wont compile. I made edit to the question – runner Oct 20 '20 at 19:40
  • What do you want to achive? Why would you want only one of the macros defined? Doesn't the using source need all of them? – the busybee Oct 21 '20 at 09:38
  • I have almost 25 such levels to debug the system. just want to reduce the code size and readability of the code. – runner Oct 22 '20 at 17:33

0 Answers0