MISRA rule 89

6.19 Preprocessing Directives

Moderators: misra-c, david ward

Locked
perrola
Posts: 3
Joined: Thu Oct 14, 2004 7:55 am
Location: Cergy Pontoise

MISRA rule 89

Post by perrola » Thu Oct 14, 2004 12:36 pm

Dear,

I have to design our new familly product SW platform.

To do this, we have introduce in our design the \"components set\" concept, that gathers components that have the same functionnal behaviour and that are interchangeable.
Let's take the example of a driver: we can have driver1 and driver2 that
are interchangeable, do the same job, and part of the same library. They
present the same interface.
During project instanciation from the SW platform, we choose one of them. To manage this, we plan to have a definition of the include file to avoid modifying a generic component that would call these drivers.

Code: Select all

#define COMP_DRIVER     \"driver1.h\"
and in all the components that use this driver, we plan to include the
appropriate header file this way:

Code: Select all

#include COMP_DRIVER
Is this a violation of the MISRA rule 89 ?

Defining the header file this way:

Code: Select all

#define COMP_DRIVER     \"../driver1/driver1.h\"
Is this a violation of the MISRA rule 89 ?

Thank you for your answer.

Best regards

Laurent Perron

[email protected]
Posts: 2
Joined: Fri Oct 01, 2004 2:03 am
Location: Livonia, MI

Post by [email protected] » Wed Dec 29, 2004 9:39 pm

Based upon what I have seen with tools, most toolsets will flag this as a violation, which is the i9ntent of the rule.

While I have had to use such constructs myself (usually as a result of non-compliant compiler ionstallations and other reasons), using #define in a #include can lead to problems, especially with dependency generation, as I have seen some dependency generation tools not perform proper substitution when generating dependencies.

Hope this helps.
Walter W. Schilling, Jr.
2004-2005 Ohio Space Grant Consortium Fellowship Recipient
Uinversity of Toledo PhD Student
MSES 1998 University of Toledo
BSEE 1997 Ohio Northern University

heptagonal

Re: MISRA rule 89

Post by heptagonal » Sun Jan 02, 2005 8:34 pm

To: Laurent Perron,

I read with interest your question about combining #define symbols inside of #include statements. I agree with all of the comments by Walter Schilling in his reply to your post.

I would also like to add some additional comments of my own.

It has been my experience that during the evolution of a long duration project, it is often necessary to reorganize directory structures and/or physical locations of source files. It is extremely counterproductive if these sorts of administrative tasks impact the actual content of source files.

For managing includes, I have adotped a coding style that follows these four rules:

(1) Never use the form #include \"...\"

(2) Always use the form #include <...>

(3) Only specify the exact filename inside of <...> and DO NOT include any directory information whatsoever.

(4) Allow the compiler tools and/or operating system environment to resolve the included filename outside of the scope of the source code.

These rules accomplish the following:

(a) Files can be relocated and directories can be restructured without having to modify source code. This is particularly important when source code has been subjected to peer review and then archived in a version control system. Having to re-review and re-archive source files that have changed for trivial reasons is a monunmental waste of time.

(b) Portability is increased by keeping operating system dependencies in the specification of directory paths (and so forth) out of the source code. For example, a relative path such as ../thisstuff/thisfile will be correct in a UNIX or LINUX environment but incorrect in a Windows environment.

(c) Resolution of include file locations can be performed using directory search lists maintained by your local compiler, or even by symbolic references if your operating system supports this (UNIX/LINUX). This centralizes information about locations of files in one place instead of having references scattered throughout the source code files themselves.

I am interested in any comments that other developers might have with regard to the MISRA-C:2004 compilance (or non-compliance) of this approach to managing source file name resolution.

Best Regards,

-Jack D. Calderon
Heptagonal Technology

perrola
Posts: 3
Joined: Thu Oct 14, 2004 7:55 am
Location: Cergy Pontoise

Thank you ...

Post by perrola » Mon Jan 03, 2005 6:32 am

... for all these answers. They contain very interested remarks on this topic.

On my side, I had a look at the MISRA-C:2004 and it seems that the construction I proposed is accepted in rule 19.3.

Best regards

Laurent Perron

perrola
Posts: 3
Joined: Thu Oct 14, 2004 7:55 am
Location: Cergy Pontoise

Thank you ...

Post by perrola » Mon Jan 03, 2005 6:32 am

... for all these answers. They contain very interested remarks on this topic.

On my side, I had a look at the MISRA-C:2004 and it seems that the construction I proposed is accepted in rule 19.3.

Best regards

Laurent Perron

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

Post by misra-c » Thu Apr 27, 2006 12:09 pm

We agree with previous post.
---
Posted by and on behalf of
the MISRA C Working Group

Locked

Return to “6.19 Preprocessing Directives”