ccompiler-optimizationmisra

Is evaluating C expression in the function argument violating MISRA C guideline?


Now think about the following piece of code being executed in a safety critical embedded software where gcc_optimization_level is Level2 for size. Say a function, void foo(float v); is invoked as foo(a/b); where say a and b are also float. Is evaluating a C expression a/b when invoking the function foo violating any MISRA C guideline?

ps: This question is revised from the previous version that was weakly formulated last week. Now this question ensures that it is a single question, not a homework question and hopefully not driving an opinion.


Solution

  • There is nothing in MISRA C that prevents calling foo( a / b ) as long as the types are correct.

    Within MISRA C the concept of essential types is an attempt to introduce stronger typing to the C language - this is detailed in Appendix D of MISRA C:2012, with the Rule 10.x guidelines being the enforcement.

    Equally, there is nothing in MISRA C that discusses optimization levels, beyond section 4.2 "Understanding the compiler" and section 5.3.1 "Compiler configuration" which discuss requisite knowledge (not detailing any guidelines). These sections now form part of the (freely downloadable) MISRA Compliance (link updated for new website).

    Disclaimer: see profile.