Hello,
Is it possible to increment a void pointer by uint8_t, then re-cast the pointer to uint16_t variable? Something similar to the following.
void buffer[20];
void * ptr = &buffer[0];
uint16_t lg = 64000;
((uint16_t)((uint8_t*)ptr+2)) = lg;
Thanks,
-diesel
Yes. But it's a lot less messy if you don't use void types.
char buffer[20];
char* ptr = buffer;
*( unsigned short*)(ptr+2) = 64000;
//buffer[2] = 0;
//buffer[3] = 250;
Careful of little vs big endian when you do this though.
Just curious WHY one would want to do this?