R
Rohit
I am trying to initialize an array whose initializers depend on value
of Enums. I take enum and then decide the initializer value, so that
even if enum value changes because of addition to list even then I
should be able to get correct value for the array element. I need
value and state to be present in a single byte thats why I use macros.
Here is what my code look like:
typedef enum
{
SwitchIn_Neutral,
SwitchIn_Active
} SwitchIn_value_t;
typedef enum
{
VALUE_FULLVALID,
VALUE_UNAVAIL,
VALUE_INACCURATE,
VALUE_DISABLED,
VALUE_ERROR
}valueState_t;
#define VALUE_TO_BYTE(SwitchValue,Valuestate) (((0x0F
&(SwitchValue))<< 4)|(0x0F & (Valuestate)))
#define NEUTRAL_VALID VALUE_TO_BYTE(SwitchIn_Neutral,VALUE_FULLVALID)
#define ACTIVE_VALID VALUE_TO_BYTE(SwitchIn_Active,VALUE_FULLVALID)
#define DEFAULT_ERROR VALUE_TO_BYTE(SwitchIn_Neutral,VALUE_ERROR)
char DL_SwitchIn_ConfTable[3][10] =
{
{NEUTRAL_VALID,ACTIVE_VALID,NEUTRAL_VALID,ACTIVE_VALID,DEFAULT_ERROR,
DEFAULT_ERROR,NEUTRAL_VALID,ACTIVE_VALID,DEFAULT_ERROR,DEFAULT_ERROR},
{NEUTRAL_VALID,ACTIVE_VALID,DEFAULT_ERROR,DEFAULT_ERROR,NEUTRAL_VALID,
ACTIVE_VALID,DEFAULT_ERROR,DEFAULT_ERROR,NEUTRAL_VALID,ACTIVE_VALID},
{ACTIVE_VALID,NEUTRAL_VALID,ACTIVE_VALID,NEUTRAL_VALID,ACTIVE_VALID,
NEUTRAL_VALID,ACTIVE_VALID,NEUTRAL_VALID,ACTIVE_VALID,NEUTRAL_VALID}
};
But I am getting error saying 'expected an expression' at array
initialization.
I suppose my initializers are constant expressions, but what is the
reason for this error?
of Enums. I take enum and then decide the initializer value, so that
even if enum value changes because of addition to list even then I
should be able to get correct value for the array element. I need
value and state to be present in a single byte thats why I use macros.
Here is what my code look like:
typedef enum
{
SwitchIn_Neutral,
SwitchIn_Active
} SwitchIn_value_t;
typedef enum
{
VALUE_FULLVALID,
VALUE_UNAVAIL,
VALUE_INACCURATE,
VALUE_DISABLED,
VALUE_ERROR
}valueState_t;
#define VALUE_TO_BYTE(SwitchValue,Valuestate) (((0x0F
&(SwitchValue))<< 4)|(0x0F & (Valuestate)))
#define NEUTRAL_VALID VALUE_TO_BYTE(SwitchIn_Neutral,VALUE_FULLVALID)
#define ACTIVE_VALID VALUE_TO_BYTE(SwitchIn_Active,VALUE_FULLVALID)
#define DEFAULT_ERROR VALUE_TO_BYTE(SwitchIn_Neutral,VALUE_ERROR)
char DL_SwitchIn_ConfTable[3][10] =
{
{NEUTRAL_VALID,ACTIVE_VALID,NEUTRAL_VALID,ACTIVE_VALID,DEFAULT_ERROR,
DEFAULT_ERROR,NEUTRAL_VALID,ACTIVE_VALID,DEFAULT_ERROR,DEFAULT_ERROR},
{NEUTRAL_VALID,ACTIVE_VALID,DEFAULT_ERROR,DEFAULT_ERROR,NEUTRAL_VALID,
ACTIVE_VALID,DEFAULT_ERROR,DEFAULT_ERROR,NEUTRAL_VALID,ACTIVE_VALID},
{ACTIVE_VALID,NEUTRAL_VALID,ACTIVE_VALID,NEUTRAL_VALID,ACTIVE_VALID,
NEUTRAL_VALID,ACTIVE_VALID,NEUTRAL_VALID,ACTIVE_VALID,NEUTRAL_VALID}
};
But I am getting error saying 'expected an expression' at array
initialization.
I suppose my initializers are constant expressions, but what is the
reason for this error?