[svn.haxx.se] · SVN Dev · SVN Users · SVN Org · TSVN Dev · TSVN Users · Subclipse Dev · Subclipse Users · this month's index

Re: Question on extern "C" logic

From: C. Michael Pilato <cmpilato_at_collab.net>
Date: 2007-03-23 03:12:29 CET

Daniel Rall wrote:
> On Thu, 22 Mar 2007, Garrett Rooney wrote:
>> On 3/22/07, Paul Burba <pburba@collab.net> wrote:
>>> Recently when Erik added the new private header file svn_wc_private.h I
>>> noticed he didn't include the extern "C" logic:
>>> #ifdef __cplusplus
>>> extern "C" {
>>> #endif /* __cplusplus */
>>> #ifdef __cplusplus
>>> }
>>> #endif /* __cplusplus */
>>> Which seems the correct thing to do since these functions are not part
>>> of Subversion's public API and won't be called by any C++ code. We do
>>> have the extern logic in all the other include/private header files
>>> however. Is this necessary for any reason? I don't really care about
>>> changing this since it seems harmless enough, just want to make sure I
>>> understand it correctly.
>> The extern "C" statements are needed for any C header that might be
>> included by C++ code. If you don't wrap the code in extern "C" then
>> the C++ code that tries to use it will use C++ name mangling on the
>> symbols and you'll get a link error. Wrapping everything in extern
>> "C" blocks tells the C++ compiler to not mangle the symbol names so
>> everything works out at link time.
> svn_wc_private.h should have the extern "C" markup.

Dan, Garrett:

It might just be me, but I feel like I'm not seeing the real answer to
Paul's question here.

I think he understands what the extern "C" is all about. His question is
about a specific file which has the specific feature that it is *not* part
of our public API and therefore should *not* be directly included in an C++

Both your answers look like recitations of a guideline, but (to me) leave
room to wonder if the guideline applies in this specific situation. I can
read your answers as ways of saying, "It doesn't matter if the file is
included by C++ code directly or not, you need the extern "C" wrapper
regardless". But this opposes my understanding of way C/C++ interact, so
I'm left to wonder if, in fact, you both noticed that tiny little detail
about the fact svn_wc_private.h is not meant to be called by C++ code.

C. Michael Pilato <cmpilato@collab.net>
CollabNet   <>   www.collab.net   <>   Distributed Development On Demand

Received on Fri Mar 23 03:12:43 2007

This is an archived mail posted to the Subversion Dev mailing list.

This site is subject to the Apache Privacy Policy and the Apache Public Forum Archive Policy.