cast question, again

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


On Fri, Aug 29, 2008 at 05:11:23PM +0200, Egon Eckert <egon.eckert at heaven-industries.com> 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
is.

since all the remaining code also accesses the ev_watcher_time.at, 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_              http://www.deliantra.net
      ----==-- _       generation
      ---==---(_)__  __ ____  __      Marc Lehmann
      --==---/ / _ \/ // /\ \/ /      pcg at goof.com
      -=====/_/_//_/\_,_/ /_/\_\



More information about the libev mailing list