Preprocessor directives and white space

6.19 Preprocessing Directives

Moderators: misra-c, david ward

Locked
JonM
Posts: 8
Joined: Wed Apr 25, 2007 9:03 am
Location: Warwickshire

Preprocessor directives and white space

Post by JonM » Fri Jul 25, 2008 10:45 am

Rule 19.16 of MISRA C2 requires "In particular, ensure that #else and #endif directives are not followed by any characters other than white-space."

Does this rule apply to the end of the line or just the character following the 'e' or 'f'.

e.g.

Code: Select all

#endif
/* header file exclusion */
vs

Code: Select all

#endif /* header file exclusion */
vs

Code: Select all

#endif/*header file exclusion */
Which of these is allowed / preferred / not allowed by MISRA C

Jonathan

misra-c
Posts: 572
Joined: Thu Jan 05, 2006 1:11 pm

Re: Preprocessor directives and white space

Post by misra-c » Wed Sep 24, 2008 12:29 pm

Does this rule apply to the end of the line or just the character following the 'e' or 'f'.
The rule applies to all the characters following the last character of the pre-processor directive to the end of the line.
Which of these is allowed / preferred / not allowed by MISRA C
All three forms are acceptable. Style is not addressed by MISRA C.

The sentence
In particular, ensure that #else and #endif directives are not followed by any characters other than white-space.
should be read as the following
In particular, ensure that #else and #endif directives are followed by white space.
ISO-C90:6.1 states that preprocessing tokens can be separated by white space which consists of comments, or white-space characters (space, horizontal tab, new-line, vertical tab, and form-feed), or both.

[ID:0000012]
---
Posted by and on behalf of
the MISRA C Working Group

Locked

Return to “6.19 Preprocessing Directives”