Main Content

MISRA C:2012 Rule 1.1

The program shall contain no violations of the standard C syntax and constraints, and shall not exceed the implementation’s translation limits

Description

Rule Definition

The program shall contain no violations of the standard C syntax and constraints, and shall not exceed the implementation’s translation limits.

Polyspace Implementation

The rule checker checks for the issues below. Note that:

IssueC Standard DependenceAdditional Information
An integer constant falls outside the range of long int (if the constant is signed) or unsigned long int (if the constant is unsigned).Checked for C90 only.The rule checker uses your specifications for the size of a long int variable (typically 32 bits). See also Target processor type (-target).
An array of size zero is used.Checked for C90 only. 
The number of macros defined in a translation unit exceeds the limit specified in the standard.

Number of macro definitions allowed:

  • C90: 1024

  • C99 and later: 4095

A translation unit consists of a source file together with headers included directly or indirectly in the source file. These are the files necessary to create the smallest object file during compilation. The rule checker requires that the number of macros in a source plus included headers must not exceed the limit specified in the standard.

The depth of nesting in control flow statements (like if, while, etc.) exceeds the limit specified in the standard.

Maximum nesting depth allowed:

  • C90: 15

  • C99 and later: 127

 
The number of levels of inclusion using include files exceeds the limit specified in the standard.

Maximum number of levels of inclusion allowed:

  • C90: 8

  • C99 and later: 15

 
The number of members of a structure or union exceeds the limit specified in the standard.

Maximum number of members in a structure or union:

  • C90: 127

  • C99 and later: 1023

 
The number of levels of nesting in a structure exceeds the limit specified in the standard.

Maximum depth of nesting:

  • C90: 15

  • C99 and later: 63

 
The number of constants in a single enumeration exceeds the limit specified in the standard.

Maximum number of enumeration constants allowed:

  • C90: 127

  • C99 and later: 1023

 
An assembly language statement is used.Checked for all C standards. 
A nonstandard preprocessor directive is used.Checked for all C standards.The rule checker flags uses of preprocessor directives that are not found in the C standard, for instance, #ident, #alias and #assert.
Unrecognized text follows a preprocessor directive.Checked for all C standards.

The rule checker flags extraneous text following a preprocessor directive (line beginning with #). For instance:

#include <header> code

Unnamed unions or empty structs are used.Checked for C90. 
An enum contains a trailing comma.Checked for C90. 

Standard compilation error messages do not lead to a violation of this MISRA™ rule.

Tip

To mass-justify all results that come from the same cause, use the Detail column on the Results List pane. Click the column header so that all results with the same entry are grouped together. Select the first result and then select the last result while holding the Shift key. Assign a status to one of the results. If you do not see the Detail column, right-click any other column header and enable this column.

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

#include <stdio.h>
#ident "@(#) Hello World"//noncompliant
extern int func(void);

void foo(void){
	int n = 2;
	asm ("leal (%0,%0,4),%0"
         : "=r" (n)
         : "0" (n));
    
 
    // standard inline assembly
    asm ("movq $60, %rax\n\t" 
         "movq $2,  %rdi\n\t" 
         "syscall");
}

The translation unit uses the nonstandard preprocessor directive #ident. Polyspace® Flags the nonstandard syntax.

Check Information

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

Version History

Introduced in R2014b

expand all