What is the point of using #define instead of a global variable? Don't they pretty much do the same thing?
What's the difference between the two?
#define MONEY 100
int main () {
MONEY = 50;
}int MONEY = 100;
int main () {
MONEY = 50;
}const int MONEY = 100;
int main () {
MONEY = 50; // oops, won't compile (but is more useful error than the #define version, try it!)
}
So basically you're all saying that if I can use a global constant rather than a #define, I should?
__ (2 underscores) is a prefix reserved for the system/compiler. If you want to make absolutely sure your macros will never conflict with anything, you could add some underscores in front, but make sure it is not just 2 underscores. At work we use 3.
so #undef at the bottom of the .CPP files is a good idea.
[quote name='L. Spiro' timestamp='1341672034' post='4956646']
__ (2 underscores) is a prefix reserved for the system/compiler. If you want to make absolutely sure your macros will never conflict with anything, you could add some underscores in front, but make sure it is not just 2 underscores. At work we use 3.
[quote name='L. Spiro' timestamp='1341672034' post='4956646']
so #undef at the bottom of the .CPP files is a good idea.
[quote name='Cornstalks' timestamp='1341707356' post='4956770']
[quote name='L. Spiro' timestamp='1341672034' post='4956646']
so #undef at the bottom of the .CPP files is a good idea.
// Foo.cpp
#define bool int
bool FooFunction() {
return 1;
}
// Bar.cpp
bool BarFunction() {
return true;
}
// Unity.cpp
#include "foo.cpp"
#include "bar.cpp"
*snip*
[quote name='Acotoz' timestamp='1341721110' post='4956821']
#define: constant
global variable: variable
This topic has been locked by a moderator. New replies are not allowed.
With your permission, GameDev.net uses analytics cookies to understand how people use the platform. You can accept analytics or continue with necessary cookies only. Learn more