我爱占星网 我爱占星网
首页
编程
java
php
前端
首页 编程 java php 前端

go中表达结果的指针

Can I create a pointer to expression result without making new variable in Go?

package test

func foo(*uint32) {

}

func main() {
    foo(&(uint32(time.Now().Unix()))) //this line gives me error
    //cannot take the address of uint32(...
}

In the question comments, OP says that the pointers are needed for a protobuf message.

The proto package provides helper functions for creating pointers to integers and other values.

Use the proto.Uint32 function to get a pointer to a uint32.

x.Time = proto.Uint32(u)

近期文章

  • 逃避反弹戈朗
  • 初始化地图问题
  • 展平一个结构并将其转换为map [string] string [关闭]
  • 如何取消对HTML字符串中的引号进行转义
  • offset(距离末端这么远的地方开始)
  • 在Golang中动态创建结构数组
  • 在golang中一起执行bash echo和nc [重复]
  • 在go中合并两个(相同类型的)结构?
  • 如何使用反射设置用户定义类型的值?
  • JWT令牌在框架之间是否可以交叉兼容?
  • 将接口传递给函数
  • 异常JSON解析
  • 当通道关闭时,以接收通道为参数的goroutine是否停止?
  • 错误检查后的延迟放置
  • 拆分后如何将数组转换为嵌套的json对象
  • 如何使用Go获取客户端DNS IP
  • 供应商问题:在我的供应商中发现了文本包(doc.go)和转换包(examples_test.go)[重复]
  • 如何将变量作为外壳脚本文件运行
  • 我应该在程序包级别但在http处理程序之外声明变量吗?
  • 不能在参数中使用函数(func()类型)

Copyright ©2022 我爱占星 All Rights Reserved.

浙ICP备2022030071号-1

部分图文来自网络,如有侵犯您的版权,请告诉我们删除

友情链接:代码精华