I have a structure with various fields. And there are few global variables. The structure fields and the global variables (basically status-flags) denote same information. It doesnt make sense to have both of them in the RAM area. And i dnt wanna always use the '.' or '->' notations to access the structure fields as there are structure inside the structure.
Hence i feel that a way around is to use unions. But dont know how to use unions for structure in a structure type of variables. can somebody kindly give a small example or a good webpage detailing the same as i couldnt find any relevant thing on web highlighting such an example.
An example would be appreciable. Thank you in advance.
char *myvar1, *myvar2; // Global, as pointer //flag1 of st1 can be access in following manner myvar1 = &mainstruct.st1.flag1; myvar2 = &mainstruct.st1.flag2; // assuming mainstruct is also global, or adequate scope Access with *myvar1, or *myvar2 if (*myvar2 == 0x12) { // .. }