From -9115718722167032048
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f78e5,ea96cc047f6a22cc
X-Google-Attributes: gidf78e5,public
X-Google-ArrivalTime: 2001-08-10 15:12:01 PST
Path: archiver1.google.com!newsfeed.google.com!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!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: Fri, 10 Aug 2001 22:11:18 GMT
Organization: Comeau Computing; http://www.comeaucomputing.com
Approved: Fergus Henderson <fjh@cs.mu.oz.au>, moderator of comp.std.c++
Message-ID: <9l1los$281$1@panix3.panix.com>
References: <090820010209154805%BobbySchmidt@mac.com> <remove.haberg-1008011309410001@du132-226.ppp.su-anst.tninet.se>
Reply-To: comeau@comeaucomputing.com
X-Trace: mail2news.demon.co.uk 997481484 mail2news:10452 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: 70
Xref: archiver1.google.com comp.std.c++:6934

In article <remove.haberg-1008011309410001@du132-226.ppp.su-anst.tninet.se>,
Hans Aberg <remove.haberg@matematik.su.se> wrote:
>In article <090820010209154805%BobbySchmidt@mac.com>, Bobby Schmidt
><BobbySchmidt@mac.com> wrote:
>...
>  extern "C" A f(B x) {
>    // C++ definition
>  }
>Here, A and B must be C types, but the body of the function is defined
>using C++ objects.

Must be C types?   No, extern "C" does not mean the compiler
needs to enter a C mode or anything.   It is normal C++ code.

>>So I'm appealing for wisdom here: what *exactly* is the Committee's
>>intent for `extern "C"`?
>
>So the first intent I think is merely that the C++ compiler produces to
>the linker functions that can be linked together with other C functions.
>If the extern "C" functions are called in C++ code, the compiler should
>know how to link them with C++ code.

Your first sentence is only an intent (since Standard C++ doesn't
control Standard C).  But your second sentence is a requirement
(at least upon a sole C++ implementation).

>> And what of that intent is guaranteed by the
>>standard vs. simply tolerated?
>
>Now, there is another snag, namely that C++ objects may depend on
>initialization/termination. Then I think the note in verse 3.6.1:1 about
>"freestanding environments" applies, which says it is implementation
>defined. Clearly, if "main" is in C, the C compiler must know how to make
>the initialization and termination of the C++ global objects for the
>program to work. The same applies to DLL's.

It must know as a practical consideration, otherwise, right, what
you're trying to do won't work, but neither standard requires it to work.

>So for this to work in practise, the C compiler must be tuned together
>with the C++ compiler,

Right.

>but it is not required by the C++ standard

Or the C standard :)

>I think that early C/C++ compilers may not have allowed it, but more recent
>compilers do.

Some did, some didn't, some do, some don't. :)

> (My compiler, which is not the latest model, does not accept
>C linkage definitions with C++ in the body, but I think that GCC might.)

If I understand you correctly, I've never heard that before.
Can you give an example of what you mean?
-- 
Greg Comeau                 Countdown to "export": December 1, 2001
Comeau C/C++ ONLINE ==>     http://www.comeaucomputing.com/tryitout

Tasty C99/C++ Combo: Dinkumware libs + Comeau Compilers == WOW!!!

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



