Jump to content
  • Advertisement

Archived

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

RavNaz

offical line on #define's

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

  • 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!