Quote:Original post by RattenhirnQuote:Original post by RandomBystander
AFAIK, they also optimize better than const ints.
What makes you think that?
Probably because const is one of the subtle differences between C and C++. In C, const variables default to extern linkage and are not officially constants (so they can't, for example, be used to specify the length of an array in C89) so, in C, there are more contexts where a const variable will have to be treated as a regular variable by the compiler than in C++. Good practice in C isn't always good practice in C++ (and vice versa).
Quote:Original post by Ravyne
A #define, used as a constant, is roughly equivilent to a C or C++ 'const' variable except... it's address cannot be taken via the & operator
Also true of enum values.
Quote:
And the final kicker is that you can't use the string "PLASMA" anywhere in your code, or it'll be replaced by "3"
The text-replacement is smart enough to understand tokens and strings, so myPLASMA and "PLASMA string" will not be converted to my3 and "3 string". The problem is mostly with errors (You'll get a better error for "int BAR = 0;" if BAR is an enum value than if BAR is a #define constant) and with namespaces (the text-replacement isn't smart enough to understand namespaces).
Quote:
Also, no more multiplying that Matrix by PLASMA, unless you specifically define such an operation taking eMatterState as its parameter.
I don't know a lot about C++ conversions with functions, but 'g++ -Wall' doesn't even issue a warning if you multiply an enum value with a double. So, you can easily get an int from an enum, but you need a cast to go the other way around.