Quote:
Originally Posted by Peoples Army
Ok, I posted my code for a HL2 mod I'm workin on, and some one mentioned that I should use #defines in place of where I had my const set. It was a string and some integers I was setting as the mods default values.
I searched google for a few hours reading debates, and never seemed to get a definitive answer, so I was wondering if anyone could offer there knowledge please & thank you
I haven't got that far in my school's C++ book yet
|
I hate defines. They make the code look uglier, they are not programming and when they are multi line defines they piss me off. The advantages of using them in comparison to inline functions is that you have guarantee that they are inlined. So the place where they are useful is when you have a function used several times (what several times mean depends on the situation) and want to avoid calls to it.
When you have stuff like "#define x 1+3" you shouldn't be using defines because the sum will occur on every replacement and if you use "const x = 1 + 3" it will happen once at compile time.
I can't say, even when they make things faster, if they are recommendable because if the thought is to make it faster without caring with code becoming much worst to read, why not make functions in assembly also?
An example on why I don't like defines and that is a situation that happened to me:
Having a "#define max ...", code with a class that contains a method named, "max" will not compile.