I’m trying to memset an array of ints that exist inside a structure:
typedef struct _xyz {
int zList[9000];
} xyz;
int dll_tmain(void)
{
xyz *Xyz = (xyz *) calloc(10, sizeof(xyz));
memset((&Xyz[0])->zList, 1, 9000);
}
I’ve tried a lot of variations in the memset(), to no avail. Instead of being
initialized to 1, the number is some huge value;
Remember that
memsetsets each byte of an array to the same value. So you are copying, to the first 9000 bytes of the array, the byte with value 1. Assuming 4 byte integers, that means you are assigning an int with value0x01010101. But, what’s more, you are not assigning to the entire array, only the first 1/4 of it, again assuming 4 byte integers.You can’t do what you want with
memset. Use a for loop instead.