offical line on #define's

Started by
6 comments, last by RavNaz 21 years, 3 months ago
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,
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
So far, #define STRICT is my only define.
"after many years of singularity, i'm still searching on the event horizon"
All the time - inclusion guards, asm code sequences, debug aids, x macros, ...
E8 17 00 42 CE DC D2 DC E4 EA C4 40 CA DA C2 D8 CC 40 CA D0 E8 40E0 CA CA 96 5B B0 16 50 D7 D4 02 B2 02 86 E2 CD 21 58 48 79 F2 C3
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>inlineT max(const T& first, const T& second) {return (first > second)? first : second;}  


[edited by - petewood on January 22, 2003 4:23:48 AM]
And how else are you going to use the stringizing operator? Or even say "stringizing"?
#define could be used to reduce code bloating.


Update GameDev.net system time campaign: ''date ddmmHHMMYYYY''
Arguing on the internet is like running in the Special Olympics: Even if you win, you're still retarded.[How To Ask Questions|STL Programmer's Guide|Bjarne FAQ|C++ FAQ Lite|C++ Reference|MSDN]
MFC-style RTTI type macros? One header contains a couple of hundred lines of macro definitions...

This topic is closed to new replies.

Advertisement