ID:152395
 
Yeah, another "VS" topic. :P
Talking about general small number values, like bit flags for example. I noticed for example in stddef.dm, #defines and global const vars are somewhat mixed up for no apparent reason, for small non-object values. >_>

So, liek, I've been wondering, what are the benefits of each, and when should you use which?

Of course, for object-references or big values, const vars are best used. But otherwise shouldn't ya always go for #defines?
I don't think there really is a difference, for bit flags I always use #define.
In response to Xx Dark Wizard xX
Xx Dark Wizard xX wrote:
I don't think there really is a difference

There is a difference, const vars are just that, variables.
#defines are more like running a Find & Replace on your code files - they don't make actual vars.

I want to know if I should waste variables (yeah yeah, I know its redundant and everybody has tons of RAM etc etc, I dont care about that) on these things or not. Mainly wondering why they did it in stddef.dm.
A major difference is that #defines can be undefined later on, while constant variables always remain constant.
In response to Android Data
Android Data wrote:
A major difference is that #defines can be undefined later on, while constant variables always remain constant.

Another one is that you can use #ifdef and friends to cause certain code to be compiled only when something is defined.
In response to Jon88
Android Data wrote:
A major difference is that #defines can be undefined later on, while constant variables always remain constant.

Oh yeah, good call. So it there is actually some sense to replace #defines in stddef.dm with const vars and even no have no #defines there at all, though for our regular code, this is just another point for #define, pretty much.

Jon88 wrote:
Another one is that you can use #ifdef and friends to cause certain code to be compiled only when something is defined.

Yeah, though I am about on #define shortcuts for bit flags etc VS const vars here.

So sttdef.dm is just weird, they should either of made everything const so users won't be able to override\remove that, or make everything #defines so no vars are wasted. >_>