#define vs enum
- From: "K. Richard Pixley" <rich kyoto noir com>
- To: gtk-list redhat com
- Subject: #define vs enum
- Date: Sun, 24 May 1998 14:50:13 -0700
I notice that in the glib/gdk/gtk headers there are some #define's of
constants. I'd like to suggest that this is perhaps BadPractice(tm),
or at least NonOptimal(tm).
We've already committed to an ansi C compiler by using naked
prototypes in the headers. The only reasons to use #define's for
constants is either to patronize old or broken compilers, or to save a
coupla bytes in embedded apps.
If we're committed to ansi, then the old/broken compiler consideration
is a non-issue. In which case, enum's are a better bet than #define's
for two main reasons.
1) they can be type checked, avoiding many cast requirements, and
offering compiler support correct usage.
2) the value of an enum token is embedded in the object file and can
be printed with a debugger.
For the honest-to-goodness single stray constant, "const" is a
possible alternative. It allows the debugger to print the value,
though it costs a few bytes in the data section to do so.
If there's clear agreement on enums, then I'll volunteer to make the
changes throughout glib/gdk/gtk/gimp, and maybe even gnome.
] [Thread Prev