cast question, again

Marc Lehmann schmorp at
Sat Aug 30 08:08:13 CEST 2008

On Fri, Aug 29, 2008 at 05:11:23PM +0200, Egon Eckert <egon.eckert at> wrote:
> sorry about introducing the ever-appearing aliasing-warnings theme :)...  Can
> someone, please, explain why *not* doing the cast in following macro
> definition:

not doing the cast accesses the "at" member of *ev (with unknown type, but
usually the type isn't ev_watcher_time), doing the cast accesses the at
member of the ev_watcher_time struct overlaying whatever ev's real type

since all the remaining code also accesses the, leaving
out the cast allows the compiler to reorder code because can assume they
are not the same lvalues. (in practise, this doesn't happen between source
files yet, but it does happen within the same source file).

In c++, one could use an explicit static cast to typecheck, but not in C.
(in c++, of course, one could simply subclass...)

                The choice of a       Deliantra, the free code+content MORPG
      -----==-     _GNU_    
      ----==-- _       generation
      ---==---(_)__  __ ____  __      Marc Lehmann
      --==---/ / _ \/ // /\ \/ /      pcg at
      -=====/_/_//_/\_,_/ /_/\_\

More information about the libev mailing list