05-06-2012, 07:55 AM
Code:
typedef void (*fp)(STATE_MACHINE *sm, EVENT input);
struct STATE_MACHINE_
{
fp fp_cur_state;
};
void stm_Startup (STATE_MACHINE *sm, EVENT input);
Code:
STM_STATE_MACHINE *sm;
sm->fp_cur_state = &stm_Startup;
Code:
sm->fp_cur_state = stm_Startup;
I have two tools to check code for Misra C.
Checking version without & to the function pointer with Tastking I get the error:
Quote:MISRA-C rule 16.9 violation: [R] function calls with no parameters should have empty parenthesesWhat in fact means the exact rule (I guess):
Quote:MISRA-C rule 16.9 violation: [R] A function identifier shall only be used with either a preceding &, or with a parenthesised parameter list, which may be empty.
checking with PC-Lint with & I get
Quote:sm->fp_cur_state = &stm_Startup;
stateMachine.c 72 Warning 546: Suspicious use of &
What's right? I guess functionality should be the same in both cases.