assigning a structure (what is happening?)
Roland Rambau
roland at cochise.pcs.com
Mon May 7 19:15:26 AEST 1990
pete at eleazar.dartmouth.edu (Pete Schmitt) writes:
->struct inv
->{
-> long number;
-> char name[2];
->}
->struct inv func(s)
->struct inv s;
->{
-> struct inv s2;
-> s2 = s; /* is this legal? If not why not. If so why so. */
Yes, its legal ( with ANSI ). Its a structure assignment, will copy
sizeof( struct inv ) bytes of memory ( 6 byte or 8 byte or whatever
the implementor may need for alignment )
-> return(s2); /* it seems to work okay. How do the members get */
-> /* their assignment? Do pointers come to play here? */
Also legal. There are several quite different techniques to implement this;
but since s2 is an auto object, this return statement will probably imply
another 6-8 byte copy im memory.
->}
Roland Rambau
rra at cochise.pcs.com, {unido|pyramid}!pcsbst!rra, 2:507/414.2.fidonet
More information about the Comp.lang.c
mailing list