Re: Struct assignment




"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



.



Relevant Pages

  • Re: Problem in the C Structure code - pls help me.
    ... you define List as an array of 100 pointers to "struct ... All of these scribble on some unknown memory. ...
    (comp.lang.c)
  • Re: memory management
    ... I don't have a copy of the standard available to ... Accessing out of declared bounds of an array is ... floating-point and very occasionally pointers. ... This is called the 'struct hack', see 2.6 in the C FAQ at the usual ...
    (comp.lang.ada)
  • Re: Simple question, err... I think
    ... Your nodes contain no other indication of which pointers are valid, ... struct CountedObject ... int is_red; ... bool lament(char const s) ...
    (comp.programming)
  • Re: Data importing BUS ERROR
    ... You declare an array of 1000 pointers to struct. ... Then you malloc memory for 1 struct, ...
    (comp.lang.c)
  • Re: porting problems encountered
    ... Tru64 compiles long variables to size 8 bytes while VMS and HP-UX ... platform, the size of the structure would be 12 bytes. ... when it got to the AS/400 with 128 bit pointers. ... Using the struct from before: ...
    (comp.os.vms)