From 5028271321564392920
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f78e5,9d57bb38940f08c2
X-Google-Attributes: gidf78e5,public
From: Francis Glassborow <francis@robinton.demon.co.uk>
Subject: Re: References to functions allowed?
Date: 1999/01/19
Message-ID: <tv5uX1AC58o2EwG7@robinton.demon.co.uk>#1/1
X-Deja-AN: 434448181
Approved: stephen.clamage@sun.com (comp.std.c++)
References: <36A222B3.E51DFD28@ibm.net> <OxDGwfArQyo2EwCV@robinton.demon.co.uk> <xajr9ssr1qx.fsf@korrigan.inria.fr> <780f6f$kjs$1@engnews2.Eng.Sun.COM>
X-UID: 0000000001
X-Status: $$$T
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 <780f6f$kjs$1@engnews2.Eng.Sun.COM>, Steve Clamage
<stephen.clamage@sun.com> writes
>
>Gabriel Dos_Reis <gdosreis@sophia.inria.fr> writes:
>
>>Francis Glassborow <francis@robinton.demon.co.uk> writes:
>
>>[...]
>
>>> 
>>> In simple terms IMO I do not think there is any syntactic way that you
>>> can write a reference to a function (*f does not work because under the
>>> rules that is converted to a pointer)
>
>>Was that intended or just an oversight ?
>
>I think it was an oversight on Francis' part. :-)
>
>Sections 3.9.2 and 8.3.2 mention references to functions, and
>section 8.5.3 gives this example of a reference to function:
>
>    int (&rg)(int) = g; // rg refers to the function g

Well I stand corrected, but this seems to buy us nothing while meaning
that the strict rules for function names in C and C++ are different.  A
function name is always a pointer type in C which the function
'operator' dereferences.  Now presumably we have to provide a conversion
rule for g (actually see 4.3) in the above (or to convert it to a
function pointer elsewhere).  And CodeWarrior compiles such code.

However what use is it?

Suppose that we try it in a template:

template <typename T> void garbage(T t);

How are we to use this if T is a function type?

I cannot see how:

template <typename T> class rubbish { }

is any more useful.

Can anyone suggest anyway in which this facility provides any
functionality? 

Now how do I dereference a function pointer to bind it to a reference?
Is this well formed?

int fn (int);
int (*fnptr)(int) = fn;
int (&fnref)(int) = static_cast<int ()(int)> fnptr;


 

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              ]




