Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

macro NAME expansion as string c/C++

Tags:

c++

c

I want use the NAME of the macro inside the macro expansion as string.

Example:

#define DEBUG_TEST(a, ...) printf("DEBUG_TEST::%s (%d) : " a, __FUNCTION__, __LINE__, ##__VA_ARGS__)

Want to change to something that doesn't need the "DEBUG_TEST" anymore in the exapansion, but something like:

#define DEBUG_TEST(a, ...) printf(__MACRO__ "::%s (%d) : " a, __FUNCTION__, __LINE__, ##__VA_ARGS__)

Of course in my example __MACRO__ dosen't exist...

like image 222
user1464125 Avatar asked Mar 12 '26 21:03

user1464125


1 Answers

I believe this is not possible. My suggestion would be to create another macro that takes the name of the macro as argument. Then use this macro in your other macroses.

like image 55
Ivaylo Strandjev Avatar answered Mar 15 '26 11:03

Ivaylo Strandjev



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!