On Mon, Nov 06, 2017 at 11:10:45AM +0800, 元哲伟 <yuenzhe...@gmail.com> wrote: > #define ev_set_cb(ev,cb_) (ev_cb_ (ev) = (cb_), memmove(&((ev_watcher > *)(ev))->cb, &ev_cb_ (ev), sizeof (ev_cb_ (ev)))). I' m curious about the > reason why a redundant memmove is needed.
Hi, a (very) strict reading of the aliasing rules in ISO C makes the move non-redundant, as src and dst refer to different types. We don't know of any compiler who would miscompile it under optimisations, but the compilers we tested all optimised the memmove away, so it's better to have it. The memove also ensures that EV_CB_INVOKE works, as that might refer to either ev_watcher.cb, or the oriignal ev_subtype.cb member. -- The choice of a Deliantra, the free code+content MORPG -----==- _GNU_ http://www.deliantra.net ----==-- _ generation ---==---(_)__ __ ____ __ Marc Lehmann --==---/ / _ \/ // /\ \/ / schm...@schmorp.de -=====/_/_//_/\_,_/ /_/\_\ _______________________________________________ libev mailing list libev@lists.schmorp.de http://lists.schmorp.de/mailman/listinfo/libev