Jump to content
  • Advertisement
Sign in to follow this  
Zische

c++ macro

This topic is 4440 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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
Advertisement
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
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!