Main Content

MISRA C:2023 Rule 3.1

The character sequences /* and // shall not be used within a comment

Since R2024a

Description

Rule Definition

The character sequences /* and // shall not be used within a comment.

Rationale

These character sequences are not allowed in code comments because:

  • If your code contains a /* or a // in a /* */ comment, it typically means that you have inadvertently commented out code.

  • If your code contains a /* in a // comment, it typically means that you have inadvertently uncommented a /* */ comment.

Polyspace Implementation

You cannot annotate this rule in the source code.

For information on annotations, see Annotate Code and Hide Known or Acceptable Results.

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

int x;
int y;
int z;

void non_compliant_comments ( void )
{
    x = y //  	/* Non-compliant
        + z
        //  */
        ;
    z++;	//	Compliant with exception: // permitted within a // comment
}

void compliant_comments ( void )
{
    x = y /*  	Compliant
      + z
	  */
        ;
    z++;	//	Compliant with exception: // is permitted within a // comment
}

In this example, in the non_compliant_comments function, the /* character occurs in what appears to be a // comment, violating the rule. Because of the comment structure, the operation that takes place is x = y + z;. However, without the two //-s, an entirely different operation x=y; takes place. It is not clear which operation is intended.

Use a comment format that makes your intention clear. For instance, in the compliant_comments function, it is clear that the operation x=y; is intended.

Check Information

Group: Comments
Category: Required
AGC Category: Required

Version History

Introduced in R2024a