Start here

Home
About Klocwork
What's new
Fixed issues
Release notes
Installation

Reference

C/C++ checkers
Java checkers
C# checkers
MISRA C 2004 checkers
MISRA C++ 2008 checkers
MISRA C 2012 checkers
MISRA C 2012 checkers with Amendment 1
Commands
Metrics
Troubleshooting
Reference

Product components

C/C++ Integration build analysis
Java Integration build analysis
Desktop analysis
Refactoring
Klocwork Static Code Analysis
Klocwork Code Review
Structure101
Tuning
Custom checkers

Coding environments

Visual Studio
Eclipse for C/C++
Eclipse for Java
IntelliJ IDEA
Other

Administration

Project configuration
Build configuration
Administration
Analysis performance
Server performance
Security/permissions
Licensing
Klocwork Static Code Analysis Web API
Klocwork Code Review Web API

Community

View help online
Visit RogueWave.com
Klocwork Support
Rogue Wave Videos

Legal

Legal information

MISRA.TOKEN.BADCOM

Inappropriate character sequence in a comment.

MISRA 2012 C Rule 3.1: The character sequences /* and // shall not be used within a comment

Category: Required

Analysis: Decidable, Single Translation Unit

Applies to: C90, C99

Rationale

If a comment starting sequence, /* or //, occurs within a /* comment, is it quite likely to be caused by a missing */ comment ending sequence.

If a comment starting sequence occurs within a // comment, it is probably because a region of code has been commented-out using //.

Exception

The sequence // is permitted within a // comment.

Example

Consider the following code fragment:

/* some comment, end comment marker accidentally omitted

<<New Page>>

Perform_Critical_Safety_Function( X );

/* this comment is non-compliant */

In reviewing the page containing the call to the function, the assumption is that it is executed code. Because of the accidental omission of the end comment marker, the call to the safety critical function will not be executed.

In the following C99 example, the presence of // comments changes the meaning of the program:
x = y // /*
     + z 
     // */ 
    ;

This gives x = y + z; but would have been x = y; in the absence of the two // comment start sequences.

See also

Dir 4.4

MISRA-C 2004 Rule 2.3 (required): The character sequence /* shall not be used within a comment.

Inappropriate character sequence in a comment.

C does not support the nesting of comments even though some compilers support this as a language extension. A comment begins with /* and continues until the first */ is encountered. Any /* occurring inside a comment is a violation of this rule.

Example

Consider the following code fragment:

/* some comment, end comment marker accidentally omitted

<<New Page>>
Perform_Critical_Safety_Function(X);
/* this comment is not compliant */

In reviewing the page containing the call to the function, the assumption is that it is executed code.

Because of the accidental omission of the end comment marker, the call to the safety critical function will not be executed.

MISRA-C++ 2008 Rule 2-7-1 (required): The character sequence '/*' shall not be used within a C-style comment.

Rationale

C++ does not support the nesting of C-style comments even though some compilers support this as a non-portable language extension. A comment beginning with '/*' continues until the first '*/' is encountered. Any '/*' occurring inside a comment is a violation of this rule.

Example

Consider the following code fragment:

/* some comment, end comment marker accidentally omitted

Perform_Critical_Safety_Function(X);
/* this "comment" is Non-compliant */

In reviewing the code containing the call to the function, the assumption is that it is executed code. Because of the accidental omission of the end comment marker, the call to 'Perform_Critical_Safety_Function' will not be executed.