enum vs const int

Lucas Goss lgoss007 at gmail.com
Tue Mar 21 14:53:01 PST 2006


I'm working on X headers and I have a file with a lot of this:

#define XK_BackSpace 0xff08
#define XK_Tab       0xff09
#define XK_Linefeed  0xff0a
...

Well with the recent mention of size of D programs on this newsgroup, I 
decided to do a little test. I converted around 500 - 600 lines of code 
(all #define like above with some comments in between), to const uint, 
checked size, then converted those lines to using enums and checked 
size. The documentation says that enums define constants in a manner 
equivalent to: const int A = 0; ... So I was kinda surprised to find that:

#define->const uint = 246.5K
#define->enum       = 233.1K

So... It's better to use enum's? Is this by design? And if the whole 
file is just #define's like above, should it just be one big enum? Or 
multiple enum's?



More information about the Digitalmars-d mailing list