Did you use enum in your embedded programs? Is it preferable to use enum?
Response:
Response:
- enum is used in Embedded C programming
- enum is a user defined data type
- enum helps in generating sequential numbers for a given list of items
- Because of sequential number assignment changing a initial element value shall change all the corresponding elements in enum which is advantage in some scenarios
- mainly used in generating the error logs
- Meaningful description of error logs helps designer to debug the program easily
- enum supports only integer constants
- The biggest use of enum is when developing state machines
Example implementation:
typedef enum {
CMD_ERROR = 1,
PATH_ERROR,
FILE_NOT_FOUND
} ErrorCodes;
(or)
enum ErrorCodes {
CMD_ERROR = 1,
PATH_ERROR,
FILE_NOT_FOUND
} ;
(or)
enum ErrorCodes { CMD_ERROR = 1 } ;
(or)
enum ErrorCodes;
The same error logs can be represented by preprocessor directive #define as well as structure.
0 Comments