Re: Struct assignment
- From: Keith Thompson <kst-u@xxxxxxx>
- Date: Sat, 30 Jun 2007 13:30:19 -0700
Flash Gordon <spam@xxxxxxxxxxxxxxxxxx> writes:
Grey Alien wrote, On 30/06/07 17:43:
If I have the ff struct:
struct A
{
unsigned int i;
char s[LONG_ENOUGH];
} a, b;
And use them in code like this:
a.i = 42 ;
strcpy(a.s,"test");
b.i = 100 ;
b = a ;
at this point, a (bitwise?) copy of a is made to b.
It is not a bitwise copy, it is a copy of all the elements in the struct.
Yes -- and that can be, and commonly is, implemented as a bitwise copy
of the struct.
Suppose there's a gap between the members "i" and "s". After the
assignment "b = a;", the gaps in "a" and "b" may or may not have the
same contents. The assignment can be done either as a bitwise copy or
by copying the members one-by-one, leaving any gaps alone.
99% of the type, this doesn't matter because you're never going to
look at what's in the gaps anyway.
--
Keith Thompson (The_Other_Keith) kst-u@xxxxxxx <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."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
.
- References:
- Struct assignment
- From: Grey Alien
- Re: Struct assignment
- From: Flash Gordon
- Struct assignment
- Prev by Date: Re: Machine epsilon: conclusion
- Next by Date: Re: reply the answer
- Previous by thread: Re: Struct assignment
- Next by thread: Re: Struct assignment
- Index(es):
Relevant Pages
|