I hope this is not a duplicate question, but I searched in detail and did not find my specific case before.
I have a simple structure that should also have access to a simple byte array
union { struct { unsigned char a; unsigned char b;
Please note that the structure is not named and it also does not have its own member name. This means that I can use myUnion.a to access this member, and not myUnion.myStruct.a .
However, without any name, how can I get the size of the structure for myUnion.bytes[] , besides manually calculating it every time I change something?
My current workaround is to use #define to solve the problem of myUnion.myStruct , but this has a negative side effect of myUnion.myStruct my autocomplete in the editor, and also makes it difficult to understand the data structure.
Any ideas?
Note. . This runs on an 8-bit processor. No problem with word alignment, etc. However, any reservations should probably be indicated, so that someone else does not use the proposed solution improperly.
source share