duanmei2805
duanmei2805
2018-02-03 23:50

在GO中从一个结构复制到另一个结构

  • it技术
  • 互联网问答
  • IT行业问题
  • 编程语言问答
  • 计算机技术

I have two structs:

type struct1 struct{
     arr [num1]byte
}

type struct2 struct{
     b1 [n1]uint64
     b2 [n2]uint64
     b3 [n3]uint64
}

Now, I have two pointers to these structs:

p1 := new(struct1);
p2 := new(struct2);

and after some computations, I want to copy p2 to a specified part of p1. Something like:

copy(p1.arr[k:], p2);

Where k is a positive integer. It can be easily done in C using memcpy, but I could not find an easy way to do it in GO without using any external libraries. Does anyone have any suggestions? I'll really appreciate it.

  • 点赞
  • 回答
  • 收藏
  • 复制链接分享

2条回答

为你推荐

换一换