Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Please explain: why structure is used inside the union ?

Status
Not open for further replies.

cnandha19

Member level 3
Joined
Aug 28, 2015
Messages
59
Helped
1
Reputation
2
Reaction score
1
Trophy points
8
Activity points
604
Code:
union
{
  struct
  {
    unsigned bat:1;         
    unsigned F6:1;
	unsigned sw:1;
	unsigned F1:1;
	unsigned F2:1;
	unsigned F3:1;
	unsigned F4:1;
	unsigned F7:1;
  } Bit;
  unsigned char Byte;
} Flags;


1.any one explain it pls
2. why structure is used inside the union

sorry i m a learner jus now learning
 
Last edited by a moderator:

Re: Any one please explain tis

In order to achieve access to the bits of the byte
 

Depending on the processor core it is also useful for reducing the program memory usage, rather than a structure inside another. Perhaps not so useful on this case in particular on which the total amount of bits is multiple of a byte (16 bits), but at least this turns the code somewhat prone to optimize if added another 1-bit flag there.
 
Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top