Re: Struct assignment
- From: "Serve Lau" <aser@xxxx>
- Date: Sat, 30 Jun 2007 20:53:02 +0200
"Flash Gordon" <spam@xxxxxxxxxxxxxxxxxx> wrote in message
news:hhfil4xnvp.ln2@xxxxxxxxxxxxxxxxxxxxxxxxxx
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.
Question is:
1). is b.s now ptr to a.s ? (I think so)
Since b.s was not defined as a pointer, what makes you think an assignment
could magically transform it from being an array in to being a pointer?
You need to read section 6 of the comp.lang.c FAQ at http://c-faq.com/
specifically the questions dealing with whether pointers and arrays are
the same thing.
Its easy to see where the confusion comes from. There are situations where
pointers degenerate into pointers , the OP probably had that in mind
.
- Follow-Ups:
- Re: Struct assignment
- From: Richard Heathfield
- Re: Struct assignment
- From: Flash Gordon
- Re: Struct assignment
- References:
- Struct assignment
- From: Grey Alien
- Re: Struct assignment
- From: Flash Gordon
- Struct assignment
- Prev by Date: Re: compiling c application to prc (palm) tool - TPA
- Next by Date: Re: Machine epsilon: conclusion
- Previous by thread: Re: Struct assignment
- Next by thread: Re: Struct assignment
- Index(es):
Relevant Pages
|
|