#include <string>
using namespace std;
#define PRINT_INFO() printf("%s",__FUNCTION__)
#define PRINT(str,...) printf("%s %s", PRINT_INFO(), str, ##__VA_ARGS__)
int main() {
PRINT_INFO(); // expected output = main
PRINT("Hello %s", "World"); // expected output = main Hello World
return 0;
}
Consider the above code snippet in c++. My intention is to use the PRINT_INFO() macro inside PRINT() macro in a way that will also print the parameters sent from main.
However, I am getting >> Command terminated by signal 11
How can I get what I intend to get?
Think about what happens as the PRINT macro is expanded:
I don't think this is what you intended.
Perhaps you meant:
I don't see the value that having two macros adds. Another option would be:
This gives the line information as well, you can just remove that if you do not want it.