Main Content

MISRA C:2012 Rule 1.4

Emergent language features shall not be used

Description

Rule Definition

Emergent language features shall not be used.

Rationale

Some new language features in the C11 Standard have undefined, unspecified or implementation-defined behavior. These features might also exhibit well-defined behavior that defies developer expectations. Though rule 1.3 and directive 1.1 prohibits undefined and implementation-defined behavior, to avoid well-defined behavior that defies expectations, some language features are summarily discouraged using rule 1.4.

Polyspace Implementation

The rule forbids use of all facilities in Annex K of the C11 Standard about 'Bound-checking interfaces', other than defining __STDC_WANT_LIB_EXT1__ to '0'.

Troubleshooting

If you expect a rule violation but do not see it, refer to Diagnose Why Coding Standard Violations Do Not Appear as Expected.

Examples

expand all

#define __STDC_WANT_LIB_EXT1__ 1 //Noncompliant
#include <string.h>

void Copying_functions(void) {
    char buf1[10];
    char buf2[10];
    errno_t e;  //Noncompliant
    e = memcpy_s(buf1,sizeof(buf1),buf2,5); //Noncompliant
    e = memmove_s(buf1,sizeof(buf1),buf2,5); //Noncompliant
    e = strcpy_s(buf1,sizeof(buf1),buf2); //Noncompliant
    e = strncpy_s(buf1,sizeof(buf1),buf2,5); //Noncompliant
}

In this example, the macro __STDC_WANT_LIB_EXT1__ is set to 1 so that the type errno_t as defined in the header stdlib.h can be used (in accordance with Annex K of the C11 Standard).

The checker flags both the setting of the macro to 1 and the definition of the errno_t variable, along with other functions from Annex K.

Check Information

Group: Standard C Environment
Category: Required
AGC Category: Required

Version History

Introduced in R2014b

expand all