Adventure Game Studio

AGS Support => Advanced Technical Forum => Topic started by: Retro Wolf on Tue 05/04/2016 18:27:59

Title: #define vs int
Post by: Retro Wolf on Tue 05/04/2016 18:27:59
Code (ags) Select

#define myNumber 1
int myNumber 1;


I'm interested to know what the differences are. When I use the first one; In my code I'm treating it as a constant, to avoid magic numbers (http://c2.com/cgi/wiki?MagicNumber). Is that the correct use? Are there any advantages (such as memory usage)?
Title: Re: #define vs int
Post by: Khris on Tue 05/04/2016 19:10:22
#define will basically make the compiler do a Search & Replace before the compilation, afaik. Which means the memory used for a #define is essentially 0.

If you tried to actually use that snippet, the second line would turn intoint 1 1;   // or: int 1 = 1;and cause a compilation error.

Title: Re: #define vs int
Post by: Retro Wolf on Wed 06/04/2016 18:45:01
Cheers for the reply Khris!