Hi.
I have been reading about unions.
I have but together what i think is the solutions to the following:
I have a float value and i would like to easily break it into 4 bytes and view each byte. Pretty straight forward!!
So outside of main() i have this.
Code:
union
{
float AsFloat;
char AsByte;
} FloatUnion;
Inside main() i have this.
Code:
char float_union_bytes[4];
FloatUnion.AsFloat = 24.65;
float_union_bytes[0] = FloatUnion.AsByte[0];
float_union_bytes[1] = FloatUnion.AsByte[1];
float_union_bytes[2] = FloatUnion.AsByte[2];
float_union_bytes[3] = FloatUnion.AsByte[3];
VT100_Print_Hex(float_union_bytes[0], 42, 40, F_BLUE, B_BLACK, 1, 0);
VT100_Print_Hex(float_union_bytes[1], 43, 40, F_BLUE, B_BLACK, 1, 0);
VT100_Print_Hex(float_union_bytes[2], 44, 40, F_BLUE, B_BLACK, 1, 0);
VT100_Print_Hex(float_union_bytes[3], 45, 40, F_BLUE, B_BLACK, 1, 0);
The VT100_Print_hex() will print a value as hex on terminal, this is tested and working.
So when i compile the above, i get this error.
Code:
main.c:60:45: error: subscripted value is neither array nor pointer nor vector
float_union_bytes[0] = FloatUnion.AsByte[0];
I dont know what its asking me for and to me, it looks correct.
Can anyone help me with what i am missing, please.