I was wondering if theres a better way instead of casting a void pointer to uint8_t, then do arithmetic based on an offset, then cast it to uint32_t, then dereference it to get a 4byte value at that exact offset.
void * foo = malloc(1024);
uint32_t myVar;
for(int i = 0; i < 10; i++)
{
myVar = *((uint32_t*)((uint8_t *) foo + nOffset));
nOffset += 100;
}
i < 10makes more sense thani> 10here. - Ruud Heldermancharinstead ofuint8_t. It's not the bit-width you're concerned with here, but the element size of the pointer.sizeof(char)is 1, by definition. - luser drooguint8_t. While it will be no difference on just about all modern platforms, having it as the genericuint8_tgives some semantic hints when reading the code. - Some programmer dudechar. - luser droog