Skip to main content

IAR Embedded Workbench for RISC-V 3.40

COMMENT-nested

In this section:
Synopsis

Appearances of /* inside comments

Enabled by default

Yes

Severity/Certainty

Low/High

lowhigh.png
Full description

Appearances of /* inside comments. C does not support nesting of comments. This can cause confusion when some code does not execute as expected. For example: /* A comment, end comment marker accidentally omitted <<New Page>> initialize(X); /* this comment is not compliant */ In this case, X will not be initialized because the code is hidden in a comment. This check is identical to MISRAC2004-2.3, MISRAC++2008-2-7-1, MISRAC++2023-5.7.1.

Coding standards
MISRA C:2004 2.3

(Required) The character sequence /* shall not be used within a comment.

MISRA C++ 2008 2-7-1

(Required) The character sequence /* shall not be used within a C-style comment.

MISRA C++ 2023 5.7.1

(Required) The character sequence /* shall not be used within a C-style comment

Code examples

The following code example fails the check and will give a warning:

void example(void) {
	/* This comment starts here
	/* Nested comment starts here
	*/
}

The following code example passes the check and will not give a warning about this issue:

void example(void) {
	/* This comment starts here */
	/* Nested comment starts here
	*/
}