Skip to main content
gamedev.net
🔒 Locked

c++ macro

Started by Zische Apr 21, 2006 at 2:47 PM 3 replies 550+ views
Original Post
Zische
Zische
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").
Zakwayda
Zakwayda
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.
blaze02
blaze02
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.
Zische
Zische
thanks, it works!
Zische
Zische
i mean jyk's solution works
#define testmacro(message) f(#message)

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.