FAQ
The goprotobuf library <https://code.google.com/p/goprotobuf/> generates
code with pointers to numbers everywhere. This however makes it impossible
to set something to the result of an expression, because it's not a pointer.
My current solution is to use temporary variables and then point there. But
this is very verbose, so I'm asking: Is there a simpler method to point to
an expression?

Currently:
temp1 := SomeValue()
protoObj.IntVar = &temp1

I'd like to do it just in one line (currently not possible):
protoObj.IntVar = &temp1

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

Search Discussions

  • Nick at Jun 23, 2013 at 3:10 pm
    The second code line should be:
    protoObj.IntVar = &SomeValue()

    --
    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+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.
  • Rob Pike at Jun 23, 2013 at 4:40 pm
    You need to store the value returned by a function before you can take
    its address, so what you're doing is right. The return value from a
    function call is not directly addressable.

    -rob

    --
    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+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.
  • Rolf Lampa at Jun 23, 2013 at 5:04 pm
    Den söndagen den 23:e juni 2013 kl. 18:40:06 UTC+2 skrev Rob Pike:
    You need to store the value returned by a function before you can take
    its address, so what you're doing is right. The return value from a
    function call is not directly addressable.
    Perhaps what he wants is a function which (should) return the pointer?

    // Rolf Lampa

    --
    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+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.
  • David DENG at Jun 24, 2013 at 1:16 am
    A second paramter for buildin-in function new will help, then it can be
    written as:

    protoObj.IntVal = new(int, SomeValue())


    David
    On Monday, June 24, 2013 12:40:06 AM UTC+8, Rob Pike wrote:

    You need to store the value returned by a function before you can take
    its address, so what you're doing is right. The return value from a
    function call is not directly addressable.

    -rob
    --
    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+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.
  • John Asmuth at Jun 24, 2013 at 2:21 am
    why would we overload new() just to remove a perfectly clear line of code,
    now and then?
    On Sunday, June 23, 2013 9:16:28 PM UTC-4, David DENG wrote:

    A second paramter for buildin-in function new will help, then it can be
    written as:

    protoObj.IntVal = new(int, SomeValue())


    David
    On Monday, June 24, 2013 12:40:06 AM UTC+8, Rob Pike wrote:

    You need to store the value returned by a function before you can take
    its address, so what you're doing is right. The return value from a
    function call is not directly addressable.

    -rob
    --
    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+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.
  • Andrew Gerrand at Jun 24, 2013 at 2:50 am
    Just import "code.google.com/p/goprotobuf/proto" and use proto.Int

    protoObj.IntVar = proto.Int(SomeValue())

    On 24 June 2013 01:10, Nick wrote:

    The second code line should be:
    protoObj.IntVar = &SomeValue()

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

    --
    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+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.
  • Zeebo at Jun 23, 2013 at 5:37 pm
    The code.google.com/p/goprotobuf/proto package has a bunch of functions
    that take a value and return a pointer,
    like http://godoc.org/code.google.com/p/goprotobuf/proto#Int

    This way you can do things like:

    m := SomeMessage{
         IntField: proto.Int(5),
    }

    On Sunday, June 23, 2013 11:04:20 AM UTC-4, Nick wrote:

    The goprotobuf library <https://code.google.com/p/goprotobuf/> generates
    code with pointers to numbers everywhere. This however makes it impossible
    to set something to the result of an expression, because it's not a pointer.
    My current solution is to use temporary variables and then point there.
    But this is very verbose, so I'm asking: Is there a simpler method to point
    to an expression?

    Currently:
    temp1 := SomeValue()
    protoObj.IntVar = &temp1

    I'd like to do it just in one line (currently not possible):
    protoObj.IntVar = &temp1
    --
    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+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupgolang-nuts @
categoriesgo
postedJun 23, '13 at 3:04p
activeJun 24, '13 at 2:50a
posts8
users7
websitegolang.org

People

Translate

site design / logo © 2021 Grokbase