Reputation: 3825
How to get the macro name inside a macro? Say we have:
#include <iostream>
using std::cout;
using std::endl;
#define MACRO() \
cout << __MACRO_NAME__ << endl
int main () {
MACRO();
return 0;
}
Expected output:
MACRO
Upvotes: 1
Views: 1425
Reputation: 422
Did little bit of research and I don't think that is doable in c++.
But you could use this:
#define MACRO2(x) cout << #x << endl
#define MACRO MACRO2(MACRO)
In this you can use MACRO2
to do the task of MACRO
and you can also access name of MACRO
as an argument x
.
Upvotes: 2