offical line on #define's
OK guyz, just a quick question.
How many of you guys use #define? or do you use alternatives? Any trade-offs??
Thats it...pretty simple..
Cheerz,
In C, there is little option but to use #define if you want, say inline functions (macros) or compile time constants (maybe you could use an enum for the compile time constant).
In C++, you have alternatives - you can use the const keyword for compile-time constants and inline functions to replace your macros.
Thats just a general overview, look at a book or the web for more info.
-Mezz
In C++, you have alternatives - you can use the const keyword for compile-time constants and inline functions to replace your macros.
Thats just a general overview, look at a book or the web for more info.
-Mezz
I only really use inclusion guards and conditional compilation, in my own work. I use libraries which pretty much require me to use their macros (mfc, boost).
templates are the best thing to replace #define macro functions
eg
[edited by - petewood on January 22, 2003 4:23:48 AM]
templates are the best thing to replace #define macro functions
eg
#define max(a,b) (((a) > (b)) ? (a) : (b))
template<typename T>inlineT max(const T& first, const T& second) {return (first > second)? first : second;}
[edited by - petewood on January 22, 2003 4:23:48 AM]
#define
could be used to reduce code bloating. Update GameDev.net system time campaign:
''date ddmmHHMMYYYY''
MFC-style RTTI type macros? One header contains a couple of hundred lines of macro definitions...
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement