I would like to avoid using memset()
on a structure like this:
typedef struct {
int size;
float param1;
} StructA;
typedef struct {
StructA a;
unsigned int state;
float param2;
} Object;
Can I do something like this (pseudo code, I can't check right now)?
Object obj;
int *adr = (int*)&obj;
for (int i; i < sizeof(obj); i++) {
*adr++ = 0;
}
Will it set every member of obj to zero?
EDIT: to answer questions on comments.
I have been working on some cases (with uni-type structures), where memset
is twice as slow than initializing by hand. So I will consider trying initializing multi-type structure as well.
Avoiding memcpy()
would be nice too (avoiding the <string.h>
lib).