Address of function

118 views
Skip to first unread message

viktor...@gmail.com

unread,
Apr 14, 2020, 7:50:58 AM4/14/20
to golang-nuts
Hi,

What is the reason for not allowing taking the address of a function return value, ie having to assign it to a variable first?

See https://play.golang.org/p/rjLwiVmikMc

Regards

Viktor Ogeman

unread,
Apr 14, 2020, 11:44:06 AM4/14/20
to Michał Łowicki, golang-nuts
Thanks


Sent from my phone

On 14 Apr 2020, at 15:34, Michał Łowicki <mlow...@gmail.com> wrote:


Please take a look at one of old threads about it - https://groups.google.com/forum/#!topic/golang-nuts/reaIlFdibWU.

--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/391875fe-946a-4456-bd67-ddecd581a917%40googlegroups.com.


--
BR,
Michał Łowicki

Michał Łowicki

unread,
Apr 14, 2020, 12:20:46 PM4/14/20
to viktor...@gmail.com, golang-nuts
Please take a look at one of old threads about it - https://groups.google.com/forum/#!topic/golang-nuts/reaIlFdibWU.

On Tue, Apr 14, 2020 at 12:50 PM <viktor...@gmail.com> wrote:
--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/391875fe-946a-4456-bd67-ddecd581a917%40googlegroups.com.


--
BR,
Michał Łowicki

ben....@compass.com

unread,
Apr 14, 2020, 8:14:47 PM4/14/20
to golang-nuts
I also wanted this (when I was learning Go I just assumed & would work in front of any expression, including function calls). I opened proposal https://github.com/golang/go/issues/22647 where there was some discussion, and further discussion over at https://github.com/golang/go/issues/9097, which is still open.

The TLDR is:

* Allowing taking the address of arbitrary expressions like &"foo" and &(1+2) is probably a bad idea
* Using the syntax &T(V), e.g., &int64(v), is a reasonable idea and might have a chance
* Generics would allow a generic addr.P() function to take the address of an arbitrary value, making this unnecessary

-Ben
Reply all
Reply to author
Forward
0 new messages