Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Goto to simulate Exceptions
#4
1) The normal way to solve the above problem is a flag

foo( )
{
int sem_is_locked = FALSE;

LOCK(sem); sem_is_locked = TRUE;


ER_EXIT:
if (sem_is_locked)
UNLOCK(sem)

}

In some cases, this type of technique would be necessary even if you don't use the macros.


2) I understand your comment,

Quote:The code appears like a functions call sequence (only one code path), but in fact no

however in practice the use of the macro is not isolated so that the programmer needs to work out what to do. It appears on every line where these is a function call. It is a system wide idiom which becomes part of the language - in fact it used more often then \"if\"s and \"while\"s - think of it as a language extension.

3) my real question is not is it part of MISRA - the real question is why it isn't - I claim that is should be mandated :-)

There is no doubt that it leads to cleaner and more robust code - my examples are simple - the more complex the code - the more it is justified
In the end of the day - isn't this MISRAs goal ?

Is MISRA carved in stone or is there a process to change MISRA ?

Another comment;

The same technique is used to do have a single exit point instead of doing \"returns\" in the middle of the code, or using complicated if structures.

What do you think of this use ? The alternatives are much less robust and less readable.



[/u]


Messages In This Thread

Forum Jump:


Users browsing this thread: 1 Guest(s)