Alex Rivera | Logout

#define or enum?

Asked 2010-06-28T17:42:05.910
24

Possible Duplicate:
Why use enum when #define is just as efficient?

When programming in C, is it better practice to use #define statements or enums for states in a state machine?

c
Edit
Report

1 Answer

8

I prefer enum. They are more compact and are 'safer'. You can also imply order in an enum, which might be helpful in a state machine. #defines should be avoided if possible, since they will overwrite all occurrences in source, which can lead to some unintended actions which are difficult to debug.

answered 2010-06-28T17:44:44.287

Your Answer