From -1866635217741129790
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f78e5,ea96cc047f6a22cc
X-Google-Attributes: gidf78e5,public
X-Google-ArrivalTime: 2001-08-11 05:14:01 PST
Path: archiver1.google.com!newsfeed.google.com!newsfeed.stanford.edu!news.tele.dk!small.news.tele.dk!212.74.64.35!colt.net!dispose.news.demon.net!news.demon.co.uk!demon!mail2news.demon.co.uk!not-for-mail
From: "James Russell Kuyper Jr." <kuyper@wizard.net>
Newsgroups: comp.std.c++
Subject: Re: extern "C" -- what is the intent?
Date: Sat, 11 Aug 2001 12:13:32 GMT
Organization: Posted via Supernews, http://www.supernews.com
Approved: Fergus Henderson <fjh@cs.mu.oz.au>, moderator of comp.std.c++
Message-ID: <3B74739E.54485C0C@wizard.net>
References: <090820010209154805%BobbySchmidt@mac.com> <remove.haberg-1008011309410001@du132-226.ppp.su-anst.tninet.se> <rjRvUrB1oAd7Ew7$@ntlworld.com> <remove.haberg-1008012124210001@du136-226.ppp.su-anst.tninet.se>
X-Trace: mail2news.demon.co.uk 997532017 mail2news:16009 mail2news mail2news.demon.co.uk
X-Complaints-To: abuse@demon.net
X-Mail2News-Path: news.demon.net!mulga.cs.mu.oz.au
X-Authentication-Warning: mulga.cs.mu.OZ.AU: fjh set sender to devnull@stump.algebra.com using -f
X-Robomod: STUMP, ichudov@algebra.com (Igor Chudov)
X-Accept-Language: en
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Lines: 58
Xref: archiver1.google.com comp.std.c++:6938

Hans Aberg wrote:
> 
> In article <rjRvUrB1oAd7Ew7$@ntlworld.com>, Francis Glassborow
> <francisG@robinton.demon.co.uk> wrote:
> >>Here, A and B must be C types
> >
> >What are those, and how do you come by that requirement? I am not aware
> >that the Standard imposes any such restriction (though to use an extern
> >"C" function defined in C++ you need compatible parameters, C++ does
> >not, AFAIK, define such (well it does define PODs).
> 
> Well, I don't see in
>   extern "C" A f(B x) {
>     // C++ definition
>   }
> if A and B are not C types, how f could be viewed as a C function from the
> linking point of view. If they are something else, one must still be able
> to convert them to objects that the linker can view as binary C objects
> before handing them over to the linker.
> 
> Or so was my impression. If you know how it works, perhaps you should
> describe it.

A and B don't have to be C types. However, if they are not C types, then
the way in which they can be used is implementation defined. An
implementation is free to define it's C++ interfaces in such a way that
the following header file, if included in both C and C++ code, would
allow a definition of f() in one language to be called from within the
other: 

connector.h:
#ifdef __cplusplus

typedef int &A;
class MyClass{
	int i;
	int j;
};
typedef int MyClass::*B;
extern "C" A f(B);

#else

typedef int *A;
typedef long int B;
extern A f(B);

#endif

Of course, an implementation is also free to make such a program blow
up; it's implemenation-defined.

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.research.att.com/~austern/csc/faq.html                ]



