A question about Macro ev_set_cb

Marc Lehmann schmorp at schmorp.de
Tue Nov 7 14:37:40 CET 2017

On Mon, Nov 06, 2017 at 11:10:45AM +0800, 元哲伟 <yuenzhewei at 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

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
      --==---/ / _ \/ // /\ \/ /      schmorp at schmorp.de
      -=====/_/_//_/\_,_/ /_/\_\

More information about the libev mailing list