[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Including verify.h in C++ with C linkage

From: Alex
Subject: Re: Including verify.h in C++ with C linkage
Date: Sun, 17 Mar 2019 13:23:22 -0600
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/26.1 (gnu/linux)

Bruno Haible <address@hidden> writes:

> Hi Alex,
>> > Hello, I'm trying to use C++ in a project that uses Gnulib, and I need
>> > to use C linkage around a statement that eventually includes verify.h.
>> > However, this leads to the following error message:
>> >
>> >   ./lib/verify.h:178:1: error: template with C linkage
>> >    template <int w>
> You are supposed to do
>   #include "verify.h"
> not
>   extern "C" {
>   #include "verify.h"
>   }
> As far as I can see from
> https://isocpp.org/wiki/faq/mixing-c-and-cpp#include-c-hdrs-personal
> https://devzone.nordicsemi.com/f/nordic-q-a/2590/please-can-you-add-extern-c-as-appropriate-to-your-header-files
> the preferred way to include .h files in C++ is like
>   #include "verify.h"

Right, my issue was that the file I need to include has to be wrapped in
an extern "C" because I need to have C linkage with the definitions
provided, but that file in turn includes verify.h.

I suppose now that I've found out that extern "C++" works, I could wrap
the particular include verify.h statements in extern "C++" instead of
having it in upstream. Perhaps an upstream fix would help someone out in
the future, but it's not important enough to include it if it's too much

>> It figures that I found a way right after posting this; is the following
>> diff a good solution for upstream?
> Not really. We have enough work testing our .h files in 2 situations:
>   - included from C
>   - included from C++
> Making our .h file work in 3 situations
>   - included from C
>   - included from C++
>   - included from C++ inside extern "C" {}
> makes for extra effort, with no real gain.

In this case the extern "C++" turns the 3rd situation into the 2nd
situation, and is a no-op in the 2nd situation, so I'm not sure this
would involve much extra effort. As said above, though, it's not a big
deal now.

Thanks for responding.

reply via email to

[Prev in Thread] Current Thread [Next in Thread]