R
Ravikiran
Hi,
I want know the differences between Unions and Structures in C
programming.
Thank you..
I want know the differences between Unions and Structures in C
programming.
Thank you..
I want know the differences between Unions and Structures in C
programming.
The size of union is the size of its largest member. In most
implementations (but standard does *not* require it) all members of
union are placed at the same location in memory.
From 6.2.5 - 20
— A union type describes an overlapping nonempty set of member
objects, each of which has an optionally specified name and possibly
distinct type.
Also, from 6.5.8 - 5
All pointers to members of the same union object compare equal.
I'd say that pretty much gurantees that the members of a union, as you
say it, are placed at the same location in memory.
Martien
PS. quotes from n1256. Wording in actual c99 standard is identical. I
don't own a c89 copy, but in a draft for that standard, similar ior
identical wording for the above quoted is present
--
|
Martien Verbruggen | Since light travels faster than sound, is
| that why some people appear bright until you
| hear them speak?
Martien said:I'd say that pretty much gurantees that the members of a union, as you
say it, are placed at the same location in memory.
the difference basically arises in the memory allocation.....while
structure allocates memory separately to each of its members, the same
is not the case with unions..it allocates memory only to the largest
available member...the rest of them are allocated within this block of
memory only
Ravikiran said:I want know the differences between Unions and Structures in C
programming.
Ravikiran said:I want know the differences between Unions and Structures in C
programming.
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.