Actually I have some difficulties in C to cast an unsigned int variable to a union-type which is declared within the declaration of structure type.
I need to set a variable in the same way like writing the field of a union defined in a structure.
Declaration in included header file:
typedef struct {
[...]
union {
unsigned long COMPLETE_VALUE;
struct {
unsigned long UPPER:16; /* [15:0] */
unsigned long LOWER:16; /* [31:16] */
} SUB_STRUCT;
} UNION;
[...]
} STRUCT_TYPE;
Variable in c-source file:
STRUCT_TYPE *pStructure; /* the reference structure */
unsigned long dummyVar; /* dummy variable */
/* writing the upper field in the structure */
pStructure->UNION.SUB_STRUCT.UPPER = some_value;
Question: It is possible to modify the value of "dummyVar" using the internal union-types of the structure-type STRUCT_TYPE? Is it possible to cast the variable to the union defined within the structure and accessing the field of the sub-structure?
It would be really useful if the variable could be modified like shown below or in a similar way:
((<CAST>) dummyVar).UNION.SUB_STRUCT.UPPER = some_value;
Notes: - The declaration of STRUCT_TYPE cannot be changed. - The structure pStructure cannot be written or edited. - The access behavior of pStructure needs to reproduced to dummyVar.
Is this possible in C anyway?
Thank you in advance!
Martin