Sign in to follow this  
Zische

c++ macro

Recommended Posts

Hi, I need a macro like this: #define testmacro(message) f("message") void f(const char* m) { // do some stuff... } When I run this macro with testmacro(hello) it calls f("message"). Is it possible to get a macro which calls f("hello") ?? I don't want to call the macro via testmacro("hello").

Share this post


Link to post
Share on other sites
I can't remember for sure (and I'm too lazy to look it up at the moment), but you might be looking for this:
#define testmacro(message) f(#message)
However, you might consider whether a macro is the best solution for what you're trying to do.

Share this post


Link to post
Share on other sites
Thats because you are telling it to call f("message") :)
Try f(message) without the quotes. If you put quotes around your variable name, it will think its a string (quote) instead of a variable.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this