Article View: comp.windows.x
Article #38353Re: C++ and callbacks
From: Scott Turner
Date: Fri, 13 May 1994 14:41
Date: Fri, 13 May 1994 14:41
39 lines
2631 bytes
2631 bytes
In article <2q9v55$ted@bigblue.oit.unc.edu>, brandon@uncvx2.oit.unc.edu
(Brandon Van Every) wrote:
> Glenn M. Poorman (poorman@cc4032.pms.ford.com) wrote:
> : In article <2q65gv$oln@bigblue.oit.unc.edu>, brandon@uncvx2.oit.unc.edu (Brandon Van Every) writes:
> : Actually the function does not have to have "extern C" linkage. It just
> : can't be a non-static member function.
>
> I can't find anything in Stroustrup that says this will work. The default
> linkage for all functions is "C++" (p. 524). Given that, I'd say that not
> using "extern C" is rather risky.
The ARM does not, and the C++ standard will not guarantee that C code and
C++ code work together, regardless of the use of extern "C".
At present, some compilers use different, incompatible calling sequences,
based on whether a function is defined with extern "C". This flouts
the ARM's note which says that the linkage specification "does not
affect the semantics of the function". IMO it will be a violation of the
eventual C++ standard, because the standard will allow passing a pointer
to a C-linkage function to a C++ function. For example,
extern "C" int f();
extern "C++" void g(int (*)());
void foo() {
g(&f); // perfectly valid mixing linkages
}
The advice to use extern "C" is valid for the present. I just wanted
to eliminate the impression that the ARM or the C++ standard is the
basis for this advice. Nor does the ARM sanction the peculiarity of a
compiler
which uses different calling conventions based on C-linkage.
--
Scott Turner
Liant Software Corp.
959 Concord St., Framingham, MA 01701 USA
(508)872-8700
pkt@lpi.liant.com
Technical Details
Message-ID:
<pkt-130594104101@138.52.2.129>Path:
arc1-ca.pugleaf.net!bga.com!news.sprintlink.net!sundog.tiac.net!usenet.elf.com!rpi!gatech!howland.reston.ans.net!pipex!uknet!EU.net!uunet!luna!NewsWatcher!userReferences:
<pauld.767898877@sarge> <2q65gv$oln@bigblue.oit.unc.edu> <2q67fpINNgv5@eccdb1.pms.ford.com> <2q9v55$ted@bigblue.oit.unc.edu>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 109fba,ad5a39011a2d3d26 X-Google-Attributes: gid109fba,public X-Google-Thread: 103734,ad5a39011a2d3d26 X-Google-Attributes: gid103734,public X-Google-Thread: 10ba33,ad5a39011a2d3d26 X-Google-Attributes: gid10ba33,public X-Google-ArrivalTime: 1994-05-13 10:49:03 PST Newsgroups: comp.windows.x,comp.lang.c++,gnu.g++.help Path: arc1-ca.pugleaf.net!bga.com!news.sprintlink.net!sundog.tiac.net!usenet.elf.com!rpi!gatech!howland.reston.ans.net!pipex!uknet!EU.net!uunet!luna!NewsWatcher!user From: pkt@lpi.liant.com (Scott Turner) Subject: Re: C++ and callbacks Message-ID: <pkt-130594104101@138.52.2.129> Followup-To: comp.lang.c++ Sender: news@lpi.liant.com Organization: Liant Software Corp. References: <pauld.767898877@sarge> <2q65gv$oln@bigblue.oit.unc.edu> <2q67fpINNgv5@eccdb1.pms.ford.com> <2q9v55$ted@bigblue.oit.unc.edu> Date: Fri, 13 May 1994 14:41:01 GMT Lines: 39