I have a function that allows access to system variables based on a lookup code. The lookup code has an enum type.
typedef enum SystemVariable_e { INT_SYSTEM_VAR_1 = 0x10, INT_SYSTEM_VAR_2 = 0x20 //etc.. } SystemVariable_e; uint16_t ReturnValue (SystemVariable_e lookup_code) { if(lookup_code == INT_SYSTEM_VAR_1) { return system_variable_one; } //etc.. } Sometimes I need to store these system variables in a (const char *) so that they can be parsed by a function that reads strings.
To make these strings somewhat legible, I have been using #define for the lookup codes.
#define STR_SYSTEM_VAR_1 "\x10" const char * StringToParse = "\x01" STR_SYSTEM_VAR_1 "\x80"; In its current state, my code uses two different lookup codes (INT_SYSTEM_VAR_1 and STR_SYSTEM_VAR_1) which use the same underlying number (0x10) to access the same system variable (system_variable_one).
I want to either merge the #define into the enum, or add the enum to the (const char *), so that I don't have two names for one lookup code.
Here are some of the things I have tried:
//this fails but describes my goal #define STR_SYSTEM_VAR_1 "\x10" typedef enum SystemVariable_e { SYSTEM_VAR_1 = STR_SYSTEM_VAR_1[0], } SystemVariable_e; //this fails but describes my goal typedef enum SystemVariable_e { INT_SYSTEM_VAR_1 = 0x10 } SystemVariable_e; const char * StringToParse = "\x01" {INT_SYSTEM_VAR_1,'\0'} "\x80";