0

How can i copy a temp struct to an actual static struct?

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


funcCopyTempToMain(Mystruct structTemp)
{
    structMain = structTemp;
}

Something like that .. Is it legit to copy whole structs that way? i only familiar with it being legit for pointers.

schanti schul
  • 681
  • 3
  • 14

1 Answers1

0

copying with assignment operator is best same as you did in the code above.. it's easy to read, rather than copying each member over to the static struct main

from 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.

Auxilus
  • 217
  • 2
  • 9