Skip to main content

IAR Embedded Workbench for RL78 5.20

CERT-DCL31-C

In this section:
Synopsis

Declare identifiers before using them.

Enabled by default

Yes

Severity/Certainty

Low/Low

lowlow.png
Full description

The C11 Standard requires type specifiers and forbids implicit function declarations. The C90 Standard allows implicit typing of variables and functions. Consequently, some existing legacy code uses implicit typing. Some C compilers still support legacy code by allowing implicit typing, but it should not be used for new code. Such an implementation may choose to assume an implicit declaration and continue translation to support existing programs that used this feature. This check is identical to FUNC-implicit-decl, MISRAC2004-8.1, MISRAC2012-Rule-17.3.

Coding standards
CERT DCL31-C

Declare identifiers before using them

MISRA C:2004 8.1

(Required) Functions shall have prototype declarations and the prototype shall be visible at both the function definition and call.

MISRA C:2012 Rule-17.3

(Mandatory) A function shall not be declared implicitly

Code examples

The following code example fails the check and will give a warning:

#include <stddef.h>
/* #include <stdlib.h> is missing */

int main(void) {
    for (size_t i = 0; i < 100; ++i) {
        /* int malloc() assumed */
        char *ptr = (char *)malloc(0x10000000);
        *ptr = 'a';
    }
    return 0;
}

The following code example passes the check and will not give a warning about this issue:

#include <stdlib.h>

int main(void) {
    for (size_t i = 0; i < 100; ++i) {
        char *ptr = (char *)malloc(0x10000000);
        *ptr = 'a';
    }
    return 0;
}