I just have a correction to my first post:
Code:
uint8 data[2048];
uint16 *two = (uint16 *)&data;
two[42] = 2;
The second line there shouldn't have had an ampersand:
Code:
uint16 *two = (uint16 *)data;
But enough subsequent posters have said that that it shouldn't be hard to figure out.
Code:
if (within limits)
val = *((uint16 *)void_ptr+offset);
else
val = *((uint32 *)void_ptr+offset);
Yeah, that's pretty much how you have to do it. If you like, you can implement some wrapper functions to make the job easier.
Code:
/** Sets data[element] = value, where the size of each element in @a data is given by
@a size .
*/
void set(char *data, size_t element, uint32 value, enum element_size_t size) {
switch(size) {
case BITS_16:
((uint16 *)data)[element] = (uint16)value;
break;
case BITS_32:
((uint32 *)data)[element] = value;
break;
default:
/* report error */
break;
}
}
Really, it's not so bad once you add another layer of abstraction.