Velocity Reviews > Diffrence

# Diffrence

Vijay
Guest
Posts: n/a

 05-29-2006
Can you tell me what is the diffrence between structure and union.

Vijay
Guest
Posts: n/a

 05-29-2006
structure alocates diffrent locations for all it memberrs but the union
creates only a single largest location to store only one member of
union at a time.

Vijay
Guest
Posts: n/a

 05-29-2006
structure alocates diffrent locations for all it memberrs but the union
creates only a single largest location to store only one member of
union at a time.

=?ISO-8859-1?Q?Erik_Wikstr=F6m?=
Guest
Posts: n/a

 05-29-2006
On 2006-05-29 13:23, Vijay wrote:
> Can you tell me what is the diffrence between structure and union.

In a struct the members are placed on separate memory locations so in
the following example one and two does not occupy the same memory.

struct s { int i1; int i2; };

In memory it could look like this

|--------|--------|
<--i1--> <--i2-->

With a union on the other hand the members occupy the same memory
location like this:

union u { int i1; int i2; };

|--------|--------|
<--i1-->
<--i2-->

That means if you change the value of i1 you also change the value of
i2, this makes unions dangerous. Add to this the fact that the alignment
of the members in unspecified and may differ between architectures and
you quickly run into portability-issues. In short, don't use unions if
you are not 100% sure of what you are doing.

Erik Wikström
--
"I have always wished for my computer to be as easy to use as my
telephone; my wish has come true because I can no longer figure
out how to use my telephone" -- Bjarne Stroustrup

osmium
Guest
Posts: n/a

 05-29-2006
"Vijay" writes:

> structure alocates diffrent locations for all it memberrs but the union
> creates only a single largest location to store only one member of
> union at a time.

Is this some new kind of indecipherable game? Where the contestant asks a
question of his choosing and then answers it?

Tomás
Guest
Posts: n/a

 05-29-2006
Vijay posted:

> Can you tell me what is the diffrence between structure and union.

"structure" contains nine letters, three of which are vowels, six of which
are consonants.

"union" contains five ltters, three of which are vowels, two of which are
consonants.

-Tomás

W Marsh
Guest
Posts: n/a

 05-29-2006
On Mon, 29 May 2006 15:14:56 GMT, "Tomás" <No.Email@Address> wrote:

>"structure" contains nine letters, three of which are vowels, six of which
>are consonants.
>
>"union" contains five ltters, three of which are vowels, two of which are
>consonants.

"letters" contains...

Chris Hills
Guest
Posts: n/a

 05-29-2006
In article <(E-Mail Removed) .com>,
Vijay <(E-Mail Removed)> writes
>Can you tell me what is the diffrence between structure and union.
>

All structures MUST belong to a Union.

It is the Structures Union Co-operative Kabul. This is why all
structures SUCK. Structures not in a union are "un-named" or master-
less structures.

--
\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
\/\/\/\/\ Chris Hills Staffs England /\/\/\/\/
/\/\/ http://www.velocityreviews.com/forums/(E-Mail Removed) www.phaedsys.org \/\/\
\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/

Keith Thompson
Guest
Posts: n/a

 05-29-2006
"Vijay" <(E-Mail Removed)> writes:
> Can you tell me what is the diffrence between structure and union.

This must be a trick question. There is no "-" operator defined for
either structures or unions.

--
Keith Thompson (The_Other_Keith) (E-Mail Removed) <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.