From -2737185647882419010
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f78e5,9d57bb38940f08c2
X-Google-Attributes: gidf78e5,public
From: thp@vdo.ucr.edu (Tom Payne)
Subject: Re: References to functions allowed?
Date: 1999/01/19
Message-ID: <780ef3$csf$1@pravda.ucr.edu>#1/1
X-Deja-AN: 434448179
X-Nntp-Posting-Host: vdo.ucr.edu
Approved: stephen.clamage@sun.com (comp.std.c++)
References: <36A222B3.E51DFD28@ibm.net> <OxDGwfArQyo2EwCV@robinton.demon.co.uk> <780f6f$kjs$1@engnews2.Eng.Sun.COM>
X-UID: 0000000001
X-Status: $$$T
Organization: University of California, Riverside
Newsgroups: comp.std.c++
Originator: clamage@taumet


Steve Clamage (stephen.clamage@sun.com) wrote:

: 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

So what would be the semantic difference between rg and pg where pg is 
declared:

     int (*pg)(int) = g; // pg points to the function g

i.e., in what contexts would they produce different results?

This also raises a few more questions for me.  It has been my
(mis)understanding that the name of a function represents a
function-pointer value (the address of the function) in all contexts
except where it is the agrument of the sizeof operator and unary-&.

  1)  If so, then wouln't g be an rvalue in the above?  

  2)  If so, wouldn't this declaration need to be const?  

  3)  If it were const wouldn't then the type of rg be reference
      to an object of type const pointer to function-returning-int
      etc.  (Two levels of indirection.)

Tom Payne




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




