Why is this an issue?
Defining a nested single-line comment within a multi-line comment invites errors. It may lead a developer to wrongly think that the lines located
after the single-line comment are not part of the comment.
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
//
.
Noncompliant code example
/* some comment, end comment marker accidentally omitted
// Make sure this function is called in a thread safe context
Perform_Critical_Safety_Function(X);
...
/* this comment is non-compliant */
Exceptions
The sequence // is permitted within a // comment.
Resources
- CERT, MSC04-C. - Use comments consistently and in a readable fashion
- MISRA C:2004, 2.3 - The character sequence /* shall not be used within a comment.
- MISRA C++:2008, 2-7-1 - The character sequence /* shall not be used within a C-style comment.
- MISRA C:2012, 3.1 - The character sequences /* and // shall not be used within a comment