[previous] MISRA-C:2004  Rule  16.8:  (Required) [next] All exit paths from a function with non-void return type shall have an explicit return statement with an expression.
This expression gives the value that the function returns. The absence of a return with an expression leads to undefined behaviour (and the compiler may not give an error).

Example Code:


/* PRQA S 2983,3203 ++ */

#include "misra.h"
#include "m2cmex.h"

static S16 test_1608a( S16 j );


static S16 test_1608a( S16 j )
{
   S16 r;

   r = j + 2;

   return;                      /* MISRA Violation */
}

static test_1608b( void )       /* MISRA Violation - Rule 8.1 */
{                               /* MISRA Violation - Rule 8.2 */
   return;                      /* MISRA Violation */
}

static test_1608c( void )       /* MISRA Violation - Rule 8.1 */
{                               /* MISRA Violation - Rule 8.2 */
}                               /* MISRA Violation */

extern S16 test_1608( void )    /* MISRA Violation */
{
   S16 r;

   r = test_1608a( 1 )         +
       test_1608b()            +
       test_1608c();
}


QAC messages that encompass this guideline:

0745 [U] 'return;' found in '%s()', which has been defined with a non-'void' return type.
2887 Function 'main' ends with an implicit 'return' statement.
2888 This function has been declared with a non-void 'return' type but ends with an implicit 'return ;' statement.
3113 [U] 'return' statement includes no expression but function '%s()' is implicitly of type 'int'.
3114 [U] Function '%s()' is implicitly of type 'int' but ends without returning a value.


Related rules:

Rule  1.2 No reliance shall be placed on undefined or unspecified behaviour.



(c) The Motor Industry Research Association, 2004
QA C Source Code Analyser 8.1.2
MISRA-C:2004 Compliance Module 3.2
© 2013 Programming Research
www.programmingresearch.com
Personality Groups | Glossary | Message Index | MISRA-C:2004 Rule Index Contents