I have two structs that appears like:
typedef unsigned char byte;
struct my_struct_2 {
int type;
int length; //will be 2 in this case
byte value1; //MSB
byte value2; //LSB
}
struct my_struct_4 {
int type;
int length; //will be 4 in this case
byte value1; //MSB
byte value2;
byte value3;
byte value4; //LSB
}
I want to loop through the "value" members in the struct based on "length" to concatenate the byte values into one number. I am wondering if it is possible to use some sort of stringizing so that I can construct a for loop with a structure similar to this:
int value = 0;
for( int i = 1; i <= length; i++)
{
value = value << 8;
value = value & my_struct.value#i#;
}
I want to take advantage of the fact that the structs members are sequentially named.
I know that I can accomplish this task by using a pointer to the first value and incrementing the pointer. I am trying to familiarize myself more with stringizing so please refrain from a pointer like solution. Thanks!