Synopsis: | Macros should not end with a semicolon. |
Language: | C |
Severity Level: | 6 |
Category: | Preprocessing Directives |
Description: |
Justification If a macro definition ends with a semicolon, the macro caller can't use a semicolon after the macro, otherwise there will be 2 semicolons after macro expansion. Most compilers and code checkers will consider this extra semicolon as an empty statement and warn about it. The macro caller should use the semicolon because that makes code much easier to read and maintain. Example #define PTR_SANITY_CHECK( ptr ) \ /* macro definition */ ASSERT(r, PARAMETER_ERROR, ( ptr != NULL)); /* WRONG */ ASSERT(r, SOME_ERROR, TRUE) /* call in the code */ #define PTR_SANITY_CHECK( ptr ) \ /* macro definition */ ASSERT(r, PARAMETER_ERROR, ( ptr != NULL)) /* RIGHT */ ASSERT(r, SOME_ERROR, TRUE); /* call in the code */ |