How to copy a struct

Going to try to not post 1600 lines of irrelevant code. So just the snippets at the heart of the question.

I have a struct

struct timer_struct
 {
  unsigned hundred_msec:1;
  unsigned quarter_sec:1;
  unsigned half_sec:1;
  unsigned one_sec:1;
  unsigned thirty_sec:1;
  unsigned sixty_sec:1;
 };

With two instances. The first is global

volatile struct timer_struct timer_flag;

The second is local to loop()

struct timer_struct timer_task;

In loop() I have

timer_task.hundred_msec = timer_flag.hundred_msec;
  timer_flag.hundred_msec = false;
  
  timer_task.quarter_sec = timer_flag.quarter_sec;
  timer_flag.quarter_sec = false;

  timer_task.half_sec = timer_flag.quarter_sec;
  timer_flag.half_sec = false;

  timer_task.one_sec = timer_flag.one_sec;
  timer_flag.one_sec = false;

  timer_task.thirty_sec = timer_flag.thirty_sec;
  timer_flag.thirty_sec = false;

  timer_task.sixty_sec = timer_flag.sixty_sec;
  timer_flag.sixty_sec = false;

to transfer the values from the timer_flag instance to the timer_task instance, and clear the timer_flag instance.

Is there a shorter way to copy one to another? I would assume if that can be done, then a shorter way to clear the timer_flag instance.

Did you try a simple assignment?

  timer_task = timer_flag;

No. I figured that was too simple of an answer. It can't be that easy.

You could use memcpy.

Whandall:
Did you try a simple assignment?

  timer_task = timer_flag;

So, without overloading 'operator=', I guess assignment defaults to a byte-for-byte copy of a struct / class? Hadn't thought about it until now.

I think so. Identical flat structures can be copied.

Phooey. Not that easy.

timer_task = timer_flag;

results in

Arduino: 1.8.10 (Windows 10), Board: "Arduino Nano, ATmega328P (Old Bootloader)"

C:\Users\Anthony\Documents\Arduino\Pool_Heater_OIT_V3\Pool_Heater_OIT_V3.ino: In function 'void loop()':

Pool_Heater_OIT_V3:774:16: error: ambiguous overload for 'operator=' (operand types are 'timer_struct' and 'volatile timer_struct')

   timer_task = timer_flag;

                ^~~~~~~~~~

C:\Users\Anthony\Documents\Arduino\Pool_Heater_OIT_V3\Pool_Heater_OIT_V3.ino:81:8: note: candidate: timer_struct& timer_struct::operator=(const timer_struct&) <near match>

 struct timer_struct

        ^~~~~~~~~~~~

C:\Users\Anthony\Documents\Arduino\Pool_Heater_OIT_V3\Pool_Heater_OIT_V3.ino:81:8: note:   conversion of argument 1 would be ill-formed:

Pool_Heater_OIT_V3:774:16: error: binding reference of type 'const timer_struct&' to 'volatile timer_struct' discards qualifiers

   timer_task = timer_flag;

                ^~~~~~~~~~

C:\Users\Anthony\Documents\Arduino\Pool_Heater_OIT_V3\Pool_Heater_OIT_V3.ino:81:8: note: candidate: timer_struct& timer_struct::operator=(timer_struct&&) <near match>

 struct timer_struct

        ^~~~~~~~~~~~

C:\Users\Anthony\Documents\Arduino\Pool_Heater_OIT_V3\Pool_Heater_OIT_V3.ino:81:8: note:   conversion of argument 1 would be ill-formed:

Pool_Heater_OIT_V3:774:16: error: cannot bind rvalue reference of type 'timer_struct&&' to lvalue of type 'volatile timer_struct'

   timer_task = timer_flag;

                ^~~~~~~~~~

exit status 1
ambiguous overload for 'operator=' (operand types are 'timer_struct' and 'volatile timer_struct')

The second half of the question is to clear the struct.

timer_task=0;

results in

Arduino: 1.8.10 (Windows 10), Board: "Arduino Nano, ATmega328P (Old Bootloader)"

C:\Users\Anthony\Documents\Arduino\Pool_Heater_OIT_V3\Pool_Heater_OIT_V3.ino: In function 'void loop()':

Pool_Heater_OIT_V3:895:12: error: no match for 'operator=' (operand types are 'timer_struct' and 'int')

 timer_task=0;

            ^

C:\Users\Anthony\Documents\Arduino\Pool_Heater_OIT_V3\Pool_Heater_OIT_V3.ino:81:8: note: candidate: timer_struct& timer_struct::operator=(const timer_struct&)

 struct timer_struct

        ^~~~~~~~~~~~

C:\Users\Anthony\Documents\Arduino\Pool_Heater_OIT_V3\Pool_Heater_OIT_V3.ino:81:8: note:   no known conversion for argument 1 from 'int' to 'const timer_struct&'

C:\Users\Anthony\Documents\Arduino\Pool_Heater_OIT_V3\Pool_Heater_OIT_V3.ino:81:8: note: candidate: timer_struct& timer_struct::operator=(timer_struct&&)

C:\Users\Anthony\Documents\Arduino\Pool_Heater_OIT_V3\Pool_Heater_OIT_V3.ino:81:8: note:   no known conversion for argument 1 from 'int' to 'timer_struct&&'

exit status 1
no match for 'operator=' (operand types are 'timer_struct' and 'int')

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

memset