<div dir="ltr"><div dir="ltr"><br></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Mon, Feb 12, 2024 at 9:02 AM Morten Brørup <<a href="mailto:mb@smartsharesystems.com">mb@smartsharesystems.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">> From: Ferruh Yigit [mailto:<a href="mailto:ferruh.yigit@amd.com" target="_blank">ferruh.yigit@amd.com</a>]<br>
> Sent: Monday, 12 February 2024 16.43<br>
> <br>
> On 2/5/2024 9:07 PM, Morten Brørup wrote:<br>
> >> From: Tyler Retzlaff [mailto:<a href="mailto:roretzla@linux.microsoft.com" target="_blank">roretzla@linux.microsoft.com</a>]<br>
> >> Sent: Monday, 5 February 2024 18.37<br>
> >><br>
> >> On Fri, Feb 02, 2024 at 09:40:59AM +0000, Bruce Richardson wrote:<br>
> >>> On Fri, Feb 02, 2024 at 10:18:23AM +0100, Thomas Monjalon wrote:<br>
> >>>> 02/02/2024 06:13, Ashish Sadanandan:<br>
> >>>>> The header was missing the extern "C" directive which causes name<br>
> >>>>> mangling of functions by C++ compilers, leading to linker errors<br>
> >>>>> complaining of undefined references to these functions.<br>
> >>>>><br>
> >>>>> Fixes: 86c743cf9140 ("eal: define generic vector types")<br>
> >>>>> Cc: <a href="mailto:nelio.laranjeiro@6wind.com" target="_blank">nelio.laranjeiro@6wind.com</a><br>
> >>>>> Cc: <a href="mailto:stable@dpdk.org" target="_blank">stable@dpdk.org</a><br>
> >>>>><br>
> >>>>> Signed-off-by: Ashish Sadanandan <<a href="mailto:ashish.sadanandan@gmail.com" target="_blank">ashish.sadanandan@gmail.com</a>><br>
> >>>><br>
> >>>> Thank you for improving C++ compatibility.<br>
> >>>><br>
> >>>> I'm not sure what is best to fix it.<br>
> >>>> You are adding extern "C" in a file which is not directly included<br>
> >>>> by the user app. The same was done for rte_rwlock.h.<br>
> >>>> The other way is to make sure this include is in an extern "C"<br>
> >> block<br>
> >>>> in lib/eal/*/include/rte_vect.h (instead of being before the<br>
> >> block).<br>
> >>>><br>
> >>>> I would like we use the same approach for all files.<br>
> >>>> Opinions?<br>
> >>>><br>
> >>> I think just having the extern "C" guard in all files is the safest<br>
> >> choice,<br>
> >>> because it's immediately obvious in each and every file that it is<br>
> >> correct.<br>
> >>> Taking the other option, to check any indirect include file you<br>
> need<br>
> >> to go<br>
> >>> finding what other files include it and check there that a) they<br>
> have<br>
> >>> include guards and b) the include for the indirect header is<br>
> >> contained<br>
> >>> within it.<br>
> >>><br>
> >>> Adopting the policy of putting the guard in each and every header<br>
> is<br>
> >> also a<br>
> >>> lot easier to do basic automated sanity checks on. If the file ends<br>
> >> in .h,<br>
> >>> we just use grep to quickly verify it's not missing the guards.<br>
> >> [Naturally,<br>
> >>> we can do more complete checks than that if we want, but 99%<br>
> percent<br>
> >> of<br>
> >>> misses can be picked up by a grep for the 'extern "C"' bit]<br>
> >><br>
> >> so first, i agree with what you say here. but one downside i've seen<br>
> >> is that non-public symbols may end up as extern "C".<br>
> >><br>
> >> i've also been unsatisfied with the inconsistency of either having<br>
> >> includes in or outside of the guards.<br>
> >><br>
> >> a lot of dpdk headers follow this pattern.<br>
> >><br>
> >> // foo.h<br>
> >> #ifdef __cplusplus<br>
> >> extern "C" {<br>
> >> #endif<br>
> >><br>
> >> #include <stdio.h><br>
> >><br>
> >> ...<br>
> >><br>
> >> but some dpdk headers follow this pattern.<br>
> >><br>
> >> // foo.h<br>
> >> #include <stdio.h><br>
> >><br>
> >> #ifdef __cplusplus<br>
> >> extern "C"<br>
> >> #endif<br>
> >><br>
> >> ...<br>
> >><br>
> >> standard C headers include the guards so don't need to be inside the<br>
> >> extern "C" block. one minor annoyance with always including inside<br>
> the<br>
> >> block is we can't reliably provide a offer a C++-only header without<br>
> >> doing extern "C++".<br>
> ><br>
> > I would say that the first of the two above patterns is not only<br>
> annoying, it is incorrect.<br>
> > A DPDK header file should not change the meaning of any other header<br>
> files it includes.<br>
> > And although the incorrectness currently only screws up any C++ in<br>
> those header files, I still consider it a bug.<br>
> ><br>
> <br>
> Should we document the proper extern "C" usage somewhere?<br>
<br>
Good point!<br>
<br>
It could be added to § 1.4.2. Header File Guards in the Coding Style chapter of the Contributor's Guidelines.<br>
<br>
BTW, that paragraph (and its example) should be updated to reflect that alphabetical order is preferred.<br></blockquote><div><br></div><div>Was the intent of this comment that I should include this update in my patch? I'm happy to do it, but IMO the guideline update should be a separate commit.</div><div><br></div><div>It's been a month since the last activity on this thread, does someone need to sign off on this change before it can be merged?</div><div><br></div><div>Thanks,</div><div>Ashish<br></div></div></div>