On Mon, Aug 22, 2016, 19:24 <con...@superhuman.com> wrote:

> Hey All,
>
> I've been using a typedef of
>
>     type MaybeTimestamp *int64
>
> so we can JSON encode timestamps correctly, see
> https://medium.com/coding-and-deploying-in-the-cloud/time-stamps-in-golang-abcaf581b72f
> for inspriation
>
> I was surprised that the following didn't work (see
> https://play.golang.org/p/1QQylqTLkB):
>
>     func NewMaybeTimestamp(t time.Time) MaybeTimestamp {
>         return &t.Unix()
>     }
>
>     // fails with:
>     // tmp/sandbox449672725/main.go:14: cannot take the address of t.Unix()
>
> I can fix this by introducing a temporary variable:
>
>     func NewMaybeTimestamp(t time.Time) MaybeTimestamp {
>         temp := t.Unix()
>         return &temp
>     }
>
> Seeing as this is the obvious solution to this problem, I was pretty
> disappointed that the compiler couldn't insert the temporary for me.
>
> Is this something that should change, or is it just a limitation
> hard-coded by the compatibility guarantee?
>

Strictly speaking you can take the address of function's return value (eg.
https://play.golang.org/p/0PTrkWEirW). It's like taking the address of any
variable. But that's an lvalue, which &f() is not.

-- 

-j

-- 
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+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to