Compiler optimization (was: 8086 (was Re: more talking to the
> struct foo a;
> struct foo b;
> b = a; /* Legal under ANSI C! */
> I could have done:
> memcpy(b,a,sizeof(struct foo));
Well, memcpy(&b,&a,sizeof(struct foo)), actually.
> I like the first sequence though, since the intent is a bit more
> clear.
It also lets the compiler copy less than the whole struct in some
circumstances - for example, if the struct has holes:
struct foo { char c; int i; };
The compiler would be free to generate the equivalent of
b.c=a.c; b.i=a.i;
rather than the memcpy. Or for
struct foo { int i; char c; };
the compiler might well do the equivalent of memcpy(&b,&a,5) rather
than ...,8 (assuming, for brevity, today's usual 32-bit-cpu sizes, and
the obvious struct-packing conventions).
/~\ The ASCII der Mouse
\ / Ribbon Campaign
X Against HTML mouse_at_rodents.montreal.qc.ca
/ \ Email! 7D C8 61 52 5D E7 2D 39 4E F1 31 3E E8 B3 27 4B
Received on Sat Nov 15 2003 - 02:59:43 GMT
This archive was generated by hypermail 2.3.0
: Fri Oct 10 2014 - 23:36:19 BST