gpt4 book ai didi

以快速简单的方式将临时结构复制到静态结构

转载 作者:行者123 更新时间:2023-11-30 19:28:25 25 4
gpt4 key购买 nike

如何将临时结构复制到实际的静态结构?

typedef struct MyStruct {
int a;
int b;
int c:
}MyStruct ;
Mystruct structMain;


funcCopyTempToMain(Mystruct structTemp)
{
structMain = structTemp;
}

类似这样的事情..以这种方式复制整个结构是否合法?我只知道它对于指针来说是合法的。

最佳答案

使用赋值运算符进行复制最好与上面代码中的操作相同。它很容易阅读,而不是将每个成员复制到静态结构 main

来自https://stackoverflow.com/a/9127315/8701568

An important note about the copying: It's a shallow copy, just like with memcpy. That means if you have e.g. a structure containing pointers, it's only the actual pointers that will be copied and not what they point to, so after the copy you will have two pointers pointing to the same memory.

关于以快速简单的方式将临时结构复制到静态结构,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53977565/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com