Since POD struct can be copied directly, why not uses the simpler code:
UESim.S = *SE;
This is generally safer to write the code that way as you don't have to bother to know if the structure is bitwise copyable as the compiler will do the proper thing (bitwise copy for any member that do not have overloaded assignment operator).
If none of the field have overloadded assignment operator, the we can expect that the compiler will be smart enough to copy the whole structure at once.
If the code is plain C, then there are no reason why above code would be slower that calling
memcpy
manually.
But in other to do that, the structure Inside the union must be of the same type as the global structure. The best way to do this would be to modify the union like this:
union UTest
{
struct STest S;
char Buffer[sizeof(struct STest)];
};
Additionnal comments for modified question
You have modified the question in a way that it is hard to make sense of some existing answers. Essentially given that you have made important modifications, it would have been better to append it at the end of original question (as I have done here).
As mentionned in answer 4, the problem is probably in code that is not shown anyway so it is hard to help you. Using a debugger might help to figure out if the content or the pointer are modified at unexpected time.
One possibility that might explain the strange behavior might be a variable conflict where a local variable has the same name as a global variable or where name differ just a bit. For example, are you sure that you don't have
ESim
and
Esim
variables as shown in your code above. That can explain why it does not works properly.