I've coded a stateflow handler and to reduce the risk of using the state flow enums outside the stateflow handler, I've defined the stateflow enums inside the function bloc.
My code looks like:
static void RequestHandler(bool isThisRequestANewRequest)
{
typedef enum
{
STATE_NEW_REQUEST,
STATE_1,
STATE_2,
STATE_ERROR,
} States;
static States state = STATE_ERROR;
if(isThisRequestANewRequest == true)
{
state = STATE_NEW_REQUEST;
}
switch(state)
{
case STATE_NEW_REQUEST:
//init request flags
state = STATE_1;
//lint -fallthrough
case STATE_1:
//do something
break;
case STATE_2:
//do something else
break;
case STATE_ERROR:
default:
//do something in case of error
break;
}
}
Is this can be considered as a good practice? Is there any risk? Is there any cons? (maintenance, reading, ...)
One collegue of mine told me that this was not, but I'm waiting for fact based answers, not just raw opinions.
Note: My question applies to both monothreaded and multithreaded tasks.