Hi guys
I often need to clear a structure, what I am doing now is just write a function to clear one element by one element. Just wondering is it safe to clear a structure as follow code. I am using XC8 compiler.
Thanks guys!
I often need to clear a structure, what I am doing now is just write a function to clear one element by one element. Just wondering is it safe to clear a structure as follow code. I am using XC8 compiler.
Thanks guys!
Code:
// my attempt to make a struct to cover everything
typedef struct{
uint8_t blah_1;
uint16_t blah_2;
uint32_t blah_3;
foo_struct_t foo_1;
foo_union_t foo_2;
uint8_t bit_1 : 1;
...
uint8_t bit_8 : 1;
}blah_t;
void clear_struct(blah_t *blah){
uint8_t len;
len = sizeof(*blah);
for(uint8_t i = 0; i < len; i++){
blah[i] = 0;
}
}