I would like to avoid using memset()in such a structure:
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 each obj element to zero?
EDIT : answer questions about comments. I worked on some cases (with structures of the same type), where it memsetis twice as slow as manual initialization. Therefore, I will consider the possibility of initializing a multi-type structure.
Avoiding memcpy()it would be nice (avoiding <string.h>lib).
source
share