previously it was codes via #define i changed that
to enum exactly besauce i want the compiler (gcc)
to produce a warning on incomplete switch statements.
just cause my architecture is 8-bit (Amtel) i need to have 8
bit-values here, 16-bit values result in larger and slower code ;(
Then you can use the 16-bit enum type for your switch statements:
enum ow_command {
OW_SEARCH_ROM = 0xF0,
OW_MATCH_ROM = 0x55,
OW_CONDITIONAL_SEARCH_ROM = 0xEC,
OW_HANDLE_SELECT = 0x0F
};
typedef unsigned char ow_command_t;
...
ow_command_t foo = whatever;
switch((enum ow_command)foo) {
case OW_SEARCH_ROM: ...
case OW_MATCH_ROM: ...
case OW_CONDITIONAL_SEARCH_ROM: ...
case OW_HANDLE_SELECT: ...
}
Note that this will convert the value of foo (8 bits) to type enum
ow_command (16 bits) for the switch statement. If that's going to be
a performance problem, you can define a conversion macro that either
does the conversion (to get the warnings) or that does nothing (for
greater performance); you can control how the macro is defined at
compilation time:
enum ow_command {
OW_SEARCH_ROM = 0xF0,
OW_MATCH_ROM = 0x55,
OW_CONDITIONAL_SEARCH_ROM = 0xEC,
OW_HANDLE_SELECT = 0x0F
};
typedef unsigned char ow_command_t;
...
#ifdef WANT_WARNINGS
#define ENUM_OW_COMMAND(x) ((enum ow_command)(x))
#else
#define ENUM_OW_COMMAND(x) (x)
#endif
ow_command_t foo = whatever;
switch (ENUM_OW_COMMAND(foo)) {
case OW_SEARCH_ROM: ...
case OW_MATCH_ROM: ...
case OW_CONDITIONAL_SEARCH_ROM: ...
case OW_HANDLE_SELECT: ...
}
Warning: I haven't tried compiling any of this; it may be full of
typos and/or stupid errors.
All of this (potentially) makes your generated code smaller and faster
at the expense of obfuscating your source code. Like any manual
optimization, you should actually measure the performance before
deciding whether the tradeoff is worthwhile. You may even find that
your compiler, with the proper options, can do a better job of
micro-optimization than you can.