#define - preprocessor command, enumeration - in C or C ++.
It is always better to use enumerations for #define for such cases. One thing is type safety. Another is that when you have a sequence of values, you only need to indicate the beginning of the sequence in the enumeration, other values will receive sequential values.
enum { ONE = 1, TWO, THREE, FOUR };
instead
#define ONE 1 #define TWO 2 #define THREE 3 #define FOUR 4
As a side note, there are still some cases where you may need to use #define (usually for some macros, if you need to build an identifier that contains a constant), but this kind of macro is black magic, and very very rare to be way to go. If you go to these limbs, you should probably use the C ++ pattern (but if you're stuck with C ...).
kriss Jun 14 2018-10-10T00: 00-06
source share