Easy maintenance table of identifier vs. text
In our project we have hundreds of identifiers used for error codes, example:
#define SYS_FAIL_EXCEP_PREFETCH_ABORT 0
#define SYS_FAIL_EXCEP_DATA_ABORT 1
#define SYS_FAIL_EXCEP_RESET 2
#define SYS_FAIL_EXCEP_UNDEFINED 3
#define SYS_FAIL_EXCEP_RESERVED 4
#define SYS_FAIL_EXCEP_IRQ_UNVECTORED 5
One of our requirements is to print the name or text of the identifier. We
are using a lookup table for this:
typedef struct HAL_Map_Text_ID_struct
{
unsigned int id;
char const * const text;
} HAL_Map_Text_ID_t;
static const HAL_Map_Text_ID_t system_failure_text_id_map[] =
{
// ID Text
// The following text has the prefix SYS_FAIL_EXCEP_
{SYS_FAIL_EXCEP_PREFETCH_ABORT,
"PREFETCH_ABORT"},
{SYS_FAIL_EXCEP_DATA_ABORT, "DATA_ABORT"},
{SYS_FAIL_EXCEP_RESET, "RESET"},
{SYS_FAIL_EXCEP_UNDEFINED, "UNDEFINED"},
{SYS_FAIL_EXCEP_RESERVED, "RESERVED"},
{SYS_FAIL_EXCEP_IRQ_UNVECTORED,
"IRQ_UNVECTORED"},
};
Our issue is that the table and the error code list can be out of sync
when somebody adds an identifier but forgets to update the table.
Is there an idiom or other process where we can add an identifier and the
table will be updated automatically?
We would prefer a solution where the identifiers are in a header file and
the table is in a source file.
Also, if possible, the solution should be MISRA compliant.
(We are using C89 with IAR embedded workbench with target system using
ARM7 processor.)
Thanks,
No comments:
Post a Comment