R
rohit
Hi,
In my couple of years of experience, I have never found a single
instance where I needed to use unions and bitfields(though I have used
structures).I was just imagining where would these find
relevance.Though both of these(bitfields and unions) are used where
space is a constraint(so I can assume always in embedded systems,where
memory is particularly less)and we want to save space/memory.
As far as I have read, there is no difference between structs an
unions apart for saving space(that would also imply how members are
accessed in unions compared to in structs).
Can someone just give a couple of examples/scenario's where these have
actually been used or need to be used.
I was of the impression that structures and unions were user defined
data types until I came to this defination of unions from K&R "Union
is a VARIABLE that may hold (at different times) objects of different
types and sizes, while the compiler keeping track of size and
alignment requirements."
So, is an union an user defined data type or a variable.
and why is it that "A union may only be initialized with a value of
the type of its first member" from K&R ??
TIA
rohit
In my couple of years of experience, I have never found a single
instance where I needed to use unions and bitfields(though I have used
structures).I was just imagining where would these find
relevance.Though both of these(bitfields and unions) are used where
space is a constraint(so I can assume always in embedded systems,where
memory is particularly less)and we want to save space/memory.
As far as I have read, there is no difference between structs an
unions apart for saving space(that would also imply how members are
accessed in unions compared to in structs).
Can someone just give a couple of examples/scenario's where these have
actually been used or need to be used.
I was of the impression that structures and unions were user defined
data types until I came to this defination of unions from K&R "Union
is a VARIABLE that may hold (at different times) objects of different
types and sizes, while the compiler keeping track of size and
alignment requirements."
So, is an union an user defined data type or a variable.
and why is it that "A union may only be initialized with a value of
the type of its first member" from K&R ??
TIA
rohit