Path: utzoo!utgpu!jarvis.csri.toronto.edu!rutgers!tut.cis.ohio-state.edu!purdue!haven!mimsy!chris From: chris@mimsy.umd.edu (Chris Torek) Newsgroups: comp.lang.c Subject: Re: memcpy versus assignment Message-ID: <21476@mimsy.umd.edu> Date: 27 Dec 89 06:13:19 GMT References: <1657@uwm.edu> Distribution: na Organization: U of Maryland, Dept. of Computer Science, Coll. Pk., MD 20742 Lines: 42 In article <1657@uwm.edu> chad@csd4.csd.uwm.edu (D. Chadwick Gibbons) writes: >On a VAX using gcc, the following code is produced: > >; foo = bar; > subl3 $76,fp,sp > movab -64(fp),r1 > movab -76(fp),r0 > movl $12,r2 > movblk Your `VAX' GCC is producing Tahoe instructions. (The Tahoe movblk instruction corresponds fairly well to movc3 on the VAX.) As to the original question: if #define pointer_t char * /* or void * */ struct foo src, dst; (void) memcpy((pointer_t)&dst, (pointer_t)&src, len); is faster than dst = src; you have a really stupid compiler, since the assignment could be treated internally as a call to memcpy. (In analysing an assignment statement, compilers could replace the tree (assign (name dst) (name src)) with the tree (cast void (call (name memcpy) (cast pointer_t (addressof (name dst))) (cast pointer_t (addressof (name src))) (constant (sizeof (structtype foo)))) which is exactly what it would have built for the memcpy line above.) -- In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 7163) Domain: chris@cs.umd.edu Path: uunet!mimsy!chris