From -2191292566927066004
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f78e5,ea96cc047f6a22cc
X-Google-Attributes: gidf78e5,public
X-Google-ArrivalTime: 2001-08-28 07:54: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: comeau@panix.com (Greg Comeau)
Newsgroups: comp.std.c++
Subject: Re: extern "C" -- what is the intent?
Date: Tue, 28 Aug 2001 14:53:36 GMT
Organization: Comeau Computing; http://www.comeaucomputing.com
Approved: Fergus Henderson <fjh@cs.mu.oz.au>, moderator of comp.std.c++
Message-ID: <9mf2n0$7dq$1@panix3.panix.com>
References: <090820010209154805%BobbySchmidt@mac.com> <1eys049.1mtaactofnng2N%joerg.barfurth@attglobal.net> <remove.haberg-2708011912260001@du132-226.ppp.su-anst.tnine <1eytm7g.12quiy6u3s1qwN%joerg.barfurth@attglobal.net>
Reply-To: comeau@comeaucomputing.com
X-Trace: mail2news.demon.co.uk 999010425 mail2news:13124 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)
Lines: 91
Xref: archiver1.google.com comp.std.c++:7208

In article <1eytm7g.12quiy6u3s1qwN%joerg.barfurth@attglobal.net>,
Joerg Barfurth <joerg.barfurth@attglobal.net> wrote:
>Hans Aberg <remove.haberg@matematik.su.se> wrote:
>> >>   extern "C" short foo(int);
>> >> is not legal unless one has specified conversion operators
>> >>   extern "C++" int -> extern "C" int
>> >>   extern "C" short -> extern "C++" short
>
>> The main point is that
>>   extern "C++" int
>> and
>>   extern "C" int
>> need not anymore have the same underlying binary structure.
>
>Even if a language linkage does allow linking to code written in a given
>language, that does not mean that C++-declarations under that language
>linkage are textually equivalent to declarations of the same entity in
>the other language.
>
>Thus in
>  extern "C" int foo();
>
>'int' is the C++-Type int and is not necessarily identical to type int
>in all linkable C implementations.

Agreed.

>Thus the same function may need to be
>declared as
>  long foo(void);
>
>in C.

Agreed.  Perhaps even in C++ :)

>This may seem confusing for C, but it becomes clear when you consider
>that
>
>  extern "Pascal"=
>  procedure foo(i : Integer) forward;
>
>is not well-formed C++, while a C++ implementation might define that
>
>  extern "Pascal" void foo(short);
>
>can be used to declare and call in C++ code a function that is defined
>in some Pascal dialect as
>
>  procedure foo( i : Integer ) BEGIN { ... } END

Sure, the C++ side still needs to be C++.

>Thus you also don't need any 'conversion operators' to define a
>conversion between homonymous types having different binary
>representations. A C++ declaration is only concerned with C++ types,
>even under a language linkage that is not 'extern "C++"'. Thus we
>needn't require builtin support for type 'Boolean' to link to Pascal
>code.

We may not need them in the core C++ language itself, but that
doesn't mean they don't need to be somewhere.

>All that is needed is a mapping from one type system to the other which
>allows finding the corresponding declaration in the other language. This
>means that there needn't be any code or operational definitions, but
>only descriptions of correspondence. If there only are matches for a
>subset of the type system(s), then that means that only for declarations
>from that subset linkage can be achieved.

This is left vague in the Standard, but purposely so,
so I agree what you say seems possible.

>Of course there isn't anything to prevent builtin conversions either.
>Maybe a linker could automatically build stubs that do type conversions
>and adjusts calling conventions. But I don't think that could be
>considered a core part of what language linkage is intende for.

It may not be core w.r.t intent, but it sure it core as to
an expected implementation detail.
-- 
Greg Comeau                 Countdown to "export": December 1, 2001
Comeau C/C++ ONLINE ==>     http://www.comeaucomputing.com/tryitout
World Class Compilers:  Breathtaking C++, Amazing C99, Fabulous C90.
Comeau C/C++ with Dinkumware's Libraries... Have you tried it?

---
[ 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                ]



