• Advertisement

Archived

This topic is now archived and is closed to further replies.

offical line on #define's

This topic is 5507 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

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,

Share this post


Link to post
Share on other sites
Advertisement
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

Share this post


Link to post
Share on other sites
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
#define max(a,b)     (((a) > (b)) ? (a) : (b))  

template<typename T>
inline
T max(const T& first, const T& second) {
return (first > second)? first : second;
}


[edited by - petewood on January 22, 2003 4:23:48 AM]

Share this post


Link to post
Share on other sites
And how else are you going to use the stringizing operator? Or even say "stringizing"?

Share this post


Link to post
Share on other sites
#define could be used to reduce code bloating.



Update GameDev.net system time campaign: ''date ddmmHHMMYYYY''

Share this post


Link to post
Share on other sites
MFC-style RTTI type macros? One header contains a couple of hundred lines of macro definitions...

Share this post


Link to post
Share on other sites

  • Advertisement