Article View: comp.std.c++
Article #1677Re: Linkage revisited
From: John Carr
Date: Wed, 09 Aug 1995 00:03
Date: Wed, 09 Aug 1995 00:03
49 lines
2793 bytes
2793 bytes
In article <406nqo$2ul@rover.village.org>, Warner Losh <imp@village.org> wrote:
I proposed for linkage:
>>Linkage is part of the type of a function (and therefore a function
>>pointer type includes this information). A "C" function can be called
>>just like a C++ function except for overloading and possibly default
>>arguments.
>First, how do I declare a type that is a pointer to an extern "C"
>function that returns void and has no args?
>
>extern "C" { typedef void (*fp)(); }
>or
>typdef extern "C" void (*fp)();
>The second is realted. This would be the only type specifier that
>applies only to functions, and its expression is non-orthogonal to the
>rest of the language.
This is a minor annoyance. I think accepting it is worth than fixing
it (making `extern "<lang spec>"' a modifier like const or volatile
would make variables and non-function types a special case). I would
like to see `extern "<lang spec>"' changed slightly so any declaration
can follow it, including static or typedef. Ideally the spelling would
be changed not to include "extern" but it is probably too late for that.
>The bottom line is that if you want to make it part of the type of a
>function or a function pointer, much more work is needed on the draft
>to reflect this fact. I believe you will start running into some of
>the same problems that member functions:
> Casting rules. Can I cast a extern "C" to C++ and back again?
> Calling rules. When it is defined and undefined to make calls
> through these pointers.
> Size issues. Is an extern "C" pointer the same size as an
> extern "C++" pointer?
The existing answers for different type functions still work. I'm assuming
C++ inherits the C rule: a function pointer can be converted freely to other
function pointer types, but a call to a function using a pointer to a function
of a different type has undefined results. This means either the function
pointers must be the same size or the implementation must be prepared to
accept loss of information (one could imagine an implementation where C++
function pointers encoded the type of the function for run time checking;
as long as the implementation defined a "don't check" type conversions between
C and C++ function pointers would still work).
--
John Carr (jfc@mit.edu)
Technical Details
Message-ID:
<408u0t$nnv@senator-bedfellow.MIT.EDU>Path:
arc1-ca.pugleaf.net!senator-bedfellow.mit.edu!jfcReferences:
<1995Aug4.163853.11570@forte.com> <DCyD2M.46H@tigadmin.ml.com> <4068ab$o58@senator-bedfellow.mit.edu> <406nqo$2ul@rover.village.org>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!senator-bedfellow.mit.edu!jfc From: jfc@mit.edu (John Carr) Newsgroups: comp.std.c++ Subject: Re: Linkage revisited Date: 9 Aug 1995 00:03:41 GMT Organization: Massachusetts Institute Of Technology Message-ID: <408u0t$nnv@senator-bedfellow.MIT.EDU> References: <1995Aug4.163853.11570@forte.com> <DCyD2M.46H@tigadmin.ml.com> <4068ab$o58@senator-bedfellow.mit.edu> <406nqo$2ul@rover.village.org> NNTP-Posting-Host: kangaroo.mit.edu