MISRA Discussion Forums

Full Version: Rule 17.4 and main
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello,
we are facing a conflict between armclang compiler warning and mandatory MISRA Rule.
The armclang compiler V6.16 seems to require "int main", but if we adhere to Rule 17.4 adding "return 0" at the end of main it is leading to a compiler warning.
(warning: 'return' will never be executed [-Wunreachable-code-return])

Who is having the higher priority here to comply with MISRA?
Is it required to deactivate / ignore the compiler warning at this point?

According to the C Standard, 5.1.2.2.3, paragraph 1 [ISO/IEC 9899:2011], "Reaching the } that terminates the main function returns a value of 0."
Is there another possibility to comply with the MISRA Rule 17.4?
The MISRA C:2012 guidelines do not require an "int" return type from "main". The documentation for directive 1.1 states that main is commonly declared as "void main (void )" in freestanding implementations.

Therefore it is permissable to declare main to have a void return type. Your compiler may be configurable to permit a void return or the compiler warning noted, but ignored. For example, the clang compiler warning can be suppressed by using  -Wno-main-return-type

However, it is appreciated that not all compilers may have this option and the MISRA Working Group are likely to add an exception to rule 17.4 which will permit the use of  "main" with no return statement in the next Technical Corrigendum.