"aiooua" <ai****@gmail.comwrites:
please consider the following code:
---
typedef lots int; //lots of data.
typedef struct one_{
lots data;
}info;
int main(){
info i1,i2;
i1 = i2; //option 1
memcpy(i1,i2,sizeof(info)); //option2
}
It's full of syntax errors. If you want to post a code sample, please
try compiling it first, then copy-and-paste it exactly.
Your meaning happens to be clear enough in this case, but in general
you'll save us a lot of time by posting real code.
from a performance point of view, is there anything that'd make me
chose one of the options over the other?
i'm assuming option 1 would perform better. is that assumption
correct?
There's no real reason to assume that either is faster. It's possible
that the assignment might be faster, because the compiler has more
specific information available to it, but if the structure is large
enough the difference is likely to be trivial. The C standard says
nothing about performance.
In most cases, it's best to write code to be as clear as possible, and
worry about optimization only if you find that it's a real problem.
--
Keith Thompson (The_Other_Keith)
ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <* <http://users.sdsc.edu/~kst>
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"