Skip to main content

IAR Embedded Workbench for RX 5.20

MISRAC2012-Rule-12.5

In this section:
Synopsis

(Mandatory) The sizeof operator shall not have an operand which is a function parameter declared as `array of type'.

Enabled by default

Yes

Severity/Certainty

High/Medium

highmedium.png
Full description

A parameter declared as `array of type' is used as operand to the sizeof operator.

Coding standards
MISRA C:2012 Rule-12.5

(Mandatory) The sizeof operator shall not have an operand which is a function parameter declared as "array of type"

Code examples

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

int mySizeofArray(int arr[4]) {
    return sizeof(arr) / sizeof(arr[0]);
}

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

int mySizeofArray(int arr[4]) {
    return 4;
}