Game Development Community

Learn something new everyday...

by Mark Schmidt · in Torque Game Engine · 08/12/2001 (3:08 pm) · 2 replies

Okay, I thought I knew the C++ language pretty well since I use it everyday at work, but there is some code in the engine that has me perplexed. Someone want to shed some light on what the "#" symbol is used for in this macro (and I'm not talking about the # in #define, but rather pdata##name##obj)?

-----------------------------------------------------

#define PROFILE_START(name) \
static ProfilerRootData pdata##name##obj (#name); \
if(gProfiler) gProfiler->hashPush(& pdata##name##obj )

#define PROFILE_END() if(gProfiler) gProfiler->hashPop()

#else
#define PROFILE_START(x)
#define PROFILE_END()
#endif

#endif

#2
08/12/2001 (5:02 pm)
Tsk. You don't "know" C++, you slowly become acquainted with some corners of it. C++ is like the elephant in the blind person's club.

## is used to paste together two labels to make a longer label, so la##dee##dah becomes the label ladeedah. You use it in macros to make new function names in a regular manner. The # operator, on the other hand, converts a lebel to a quoted string. That's how assert() works these days (the old way was *really* scary). the following code
#define F(X) char*f##X(){return #X;}
F(Llama)
F(Vicunya)
F(Camel)
is the same as
char*fLlama() {return "Llama";}
char*fVicunya() {return "Vicunya";}
char*fCamel() {return "Camel";}