Rules 16-2-3

Moderators: david ward, misra cpp

nishiyama
Posts: 5
Joined: Tue Mar 13, 2018 7:58 am
Company: Denso Create

Rules 16-2-3

Postby nishiyama » Tue Feb 05, 2019 3:52 am

Rules 16-2-3 Rationale has the following description.

If this multiple inclusion leads to multiple or conflicting definitions,
then this can result in undefined or erroneous behaviour.

I understood that it would be a multiple definition.

However, I do not understand the case of conflicting definition.
What kind of cases are there?

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

Re: Rules 16-2-3

Postby dg1980 » Fri Feb 08, 2019 7:27 am

Hi,

i believe if you follow rule 3-2-3 strictly it is impossible to have conflicting definitions (because linker does not check types in different translation units).
If you need more background google "C traps and pitfalls" by Koenig and check chapter 3.1.

misra cpp
Posts: 145
Joined: Mon Jun 02, 2008 1:55 pm
Company: MISRA

Re: Rules 16-2-3

Postby misra cpp » Wed Apr 10, 2019 2:55 pm

We agree with dg1980. Strict adherence to 3-2-3 ensures conflicting definitions will not occur. Requiring include guards ensures that, for headers at least, 3-2-3 will be observed
Posted by and on behalf of
the MISRA C++ Working Group


Return to “6.16 Preprocessing directives (C++)”

Who is online

Users browsing this forum: No registered users and 3 guests