Rule 19.2 + TC1

6.19 Preprocessing Directives

Moderators: misra-c, david ward

Post Reply
William Forbes
Posts: 29
Joined: Wed Dec 17, 2008 9:48 pm
Company: TRW Automotive

Rule 19.2 + TC1

Post by William Forbes » Wed Apr 01, 2009 9:10 pm

Hi,

The Technical Corrigendum 1 now allows the \ character to be used in a file name path without the need for a deviation.
So what file will be included in the following:

Code: Select all

#include "test\x61test.h"
The C standard says that this is undefined.
Rule 1.2 bans undefined language features and thus a deviation is still required!

What is the point in now allowing undefined language features in one rule to avoid the need to deviate when using a system that does not allow one to write compliant code only to need a deviation against another rule. TC1 does not rescind rule 1.2?

William Forbes

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

Re: Rule 19.2 + TC1

Post by misra-c » Wed Apr 08, 2009 9:39 am

There is an anomaly with this rule which was recognised when TC1 was being drafted. The aim of permitting the use of '\' in include file names without deviating Rule 19.2 was to acknowledge that some implementations provide no other means of separating directory and file names.

While you can use '\' without deviating Rule 19.2 you will, as you point out, strictly speaking violate Rule 1.2. For clarity and completeness you should document the decision to permit use of '\'. You could, if you wish, treat this as a violation of Rule 1.2.

This topic will be reviewed during drafting of the next version of the MISRA C Guidelines.
---
Posted by and on behalf of
the MISRA C Working Group

William Forbes
Posts: 29
Joined: Wed Dec 17, 2008 9:48 pm
Company: TRW Automotive

Re: Rule 19.2 + TC1

Post by William Forbes » Wed Apr 08, 2009 9:02 pm

Hi

Thanks for clearing that up.
In my opinion, directory name should not be needed.
Most compilers allow a search path to be specified via the command line.
Then when files are rearranged (perhaps when used on another project) it is simply a case of modifying the Make file instead of all of the #include statements in all of the source files.
It also avoids the undefined behaviour.
The problem with the \ character is that it could start an escape sequence. In my example there were at least 2 possible files that could have been included (that's why the behaviour is undefined).
At least with the / character there is not the ambiguity with escape sequences (although the behaviour is still undefined). One should respect the origins of the C language and realise that / has always been the directory separator. DOS based systems came up with \ as a directory separator to throw the spanner in the works!
In my experience, most implementations will treat both \ and / as a directory separator so if one must be used the I would suggest that / is used.
It is simply not possible to specify a directory without violating rule 1.2!
I strongly feel that MISRA should not be compromised simply to pander to a compiler and/or programmers who can't be bothered to do things correctly :-)
I would go as far to request that MISRA rules ban directory information in #include files.
Also It may be worth noting that the C standard does not guarantee any more that 6 character significance in file names (no guarantee of case sensitivity) and only a single character file extension and hence it is wise to ensure that all file names are unique in the first 6 characters and only have a singe extension (.c or .h I would suggest).There are still some DOS tools around that mess long file name up and only leave the first 6 characters!

Cheers,
William Forbes

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

Re: Rule 19.2 + TC1

Post by misra-c » Tue Jun 02, 2009 10:45 am

William Forbes wrote: I strongly feel that MISRA should not be compromised simply to pander to a compiler and/or programmers who can't be bothered to do things correctly :-)
Agreed - this is our policy.
I would go as far to request that MISRA rules ban directory information in #include files.
We will certainly consider this.
---
Posted by and on behalf of
the MISRA C Working Group

Post Reply

Return to “6.19 Preprocessing Directives”