Re: A question about Macro ev_set_cb

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

A question about Macro ev_set_cb

2017-11-05 Thread 元哲伟
Hi:
I'm new in libev. When I read the header ev.h, I found ev_set_cb is defined
as
#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. And I found that the memmove
action was imported in version 4.20. Could you help me with my confusion?
Best,
Yuan
___
libev mailing list
libev@lists.schmorp.de
http://lists.schmorp.de/mailman/listinfo/libev