Thread: Iec 61508

  1. #1
    Registered User nenpa8lo's Avatar
    Join Date
    Jan 2008
    Posts
    42

    Iec 61508

    Hi All,

    Do you know why software should have only one exit from any function regarding to IEC 61508? Because it takes long way/code to get out from very 'deep code' to the end of the function and it is just easier to exit/return there.

    Sugestions?

  2. #2
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    The general principle of "one return only" is to be able to ensure that all paths exit, and that the return value can be determined at all times (it is possible in C for example to write a function that returns in several places, but that also "falls out at the end").

    If you have extremely complex functions with many levels of nesting, the suggestion would be to simplify the complex function by refactoring the function into several smaller functions, and this would simplify the logic in the complex function (because some of the complexity is now in a different function - the overall complexity is of course essentially the same)

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

Popular pages Recent additions subscribe to a feed