Rule 20.2

Moderators: misra-c, david ward

Post Reply
kalpak
Posts: 4
Joined: Tue Aug 24, 2010 9:09 am
Company: polar systems and devices

Rule 20.2

Post by kalpak » Thu Mar 08, 2018 3:06 pm

Why is
#include "c:\headers\measurement_regs.h "
non compliant to rule 20.2 due to \ in the path?

dg1980
Posts: 108
Joined: Wed Apr 27, 2016 2:33 pm
Company: Elektrobit Automotive GmbH

Re: Rule 20.2

Post by dg1980 » Fri Mar 09, 2018 8:40 am

It is undefined in the C Standard (Annex J.2) hence the MISRA rule:
The behavior is undefined in the following circumstances:
...
The characters ', \, ", //, or /* occur in the sequence between the < and >
delimiters, or the characters ', \, //, or /* occur in the sequence between the "
delimiters, in a header name preprocessing token (6.4.7).
Your example is even worse because you use a hard-coded drive letter.
Either use your compiler´s include path and change to <measurement_regs.h> or at least use relative paths with '/', e.g. <../headers/measurement_regs.h>

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

Re: Rule 20.2

Post by misra-c » Mon Apr 16, 2018 10:27 am

The "\" is not permitted for the reasons mentioned by dg1980. A deviation is necessary, which will require you to confirm that "\" behaves as required on your system. Some implementations will accept the use of "/" instead of "\".
---
Posted by and on behalf of
the MISRA C Working Group

Post Reply

Return to “8.20 Preprocessing directives”