From 2740357571085949937
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f78e5,3b852614b232b53b
X-Google-Attributes: gidf78e5,public
From: Francis Glassborow <francis@robinton.demon.co.uk>
Subject: Re: function pointer types(was: Re: atexit() behavior)
Date: 1998/12/01
Message-ID: <XyVwQmA0HBZ2EwZP@robinton.demon.co.uk>#1/1
X-Deja-AN: 417531029
Approved: stephen.clamage@sun.com (comp.std.c++)
References: <365f3482.0@10.1.1.65> <73vc1v$5oe$1@nnrp1.dejanews.com> <fneilYAeA0Y2Ewh7@robinton.demon.co.uk> <3663B9D8.283B0424@physik.tu-muenchen.de>
Organization: Southfield Microcomputer SS
Mime-Version: 1.0
Reply-To: Francis Glassborow <francisG@robinton.demon.co.uk>
Newsgroups: comp.std.c++
Originator: clamage@taumet


In article <3663B9D8.283B0424@physik.tu-muenchen.de>, Christopher
Eltschka <celtschk@physik.tu-muenchen.de> writes
>
>Francis Glassborow wrote:
>
>[...]
>
>> I think they have different signatures because the parameters are:
>> 
>> pointer to extern "C" function
>> and
>> pointer to extern "C++" function
>> 
>> and these types are differentiable.
>
>Does that mean that I can do
>
>bool is_c_function(void(*)()) { return false; }
>extern "C"
>{
>  bool is_c_function(void(*)()) { return true; }
>}
>
>and use that to differentiate between C and C++ functions?

Fundamentally  (I would have to check the fine detail), yes, but only
between functions taking no variables and returning void.  I leave you
to turn that into a template:)

>
>BTW, is there (in any direction) an automatic conversion between
>C and C++ function pointers?

Only if such a conversion can be provided.  IOW if the calling sequences
are different then you canot make the conversion.  It was because
development environments exist where the calling conventions are
different (I believe) IBM's is one such) that the decision to allow the
distinction on linkage specification was made.

>That is, is any of the following initialisations allowed?
>
>extern "C" { typedef void (*c_ptr)(); }
>typedef void (*cpp_ptr)();
>
>extern "C" void f();
>void g();
>void h() throw();
>
>cpp_ptr p1 = &f; // allowed?
only if conversion is available (implementation dependant)
>c_ptr   p2 = &g; // allowed?
likewise
>c_ptr   p3 = &h; // allowed?

I don't know, but I think that would be implementation dependant as
well.

This is an odd use of implementation dependant in so far as I think code
may or may not compile depending on the implementation.  If I am wrong
and it must compile, the result would be undefined behaviour if C and
C++ functions are not call compatible.


Francis Glassborow      Chair of Association of C & C++ Users
64 Southfield Rd
Oxford OX4 1PA          +44(0)1865 246490
All opinions are mine and do not represent those of any organisation


[ 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://reality.sgi.com/austern_mti/std-c++/faq.html              ]




