cast question, again

Marc Lehmann schmorp at schmorp.de
Sun Sep 28 04:30:29 CEST 2008


On Sat, Sep 27, 2008 at 03:47:31PM +0200, Alejandro Mery <amery at geeks.cl> wrote:
> I'm have this issue too, compiling my project with -Werror -Wall -W (by policy)

That's a pretty braindamaged policy: firstly, it means your compiler is no
longer capable of compiling standard C, but only some badly-defined dialect
of it, secondly, it means each compiler version will change the language you
are working with.

You may do that, of course, but you will not eb able to use libraries
wirtten in standard C.

> warning: dereferencing type-punned pointer will break strict-aliasing rules
> 
> and compiling stops.. but

This is most likely a compiler bug - do you still get that with current
versions of gcc?

> (&self->timeout)->at = 0.0;
> (&self->timeout)->repeat = (timeout);
> 
> without the cast, compiles flawlessly.

It compiles, and is broken, yes, as it allows the optimiser to drop your
assigments now, as per ISO C language rules.

The reason those warnings are warnings is that the compiler cannot know
for sure. While some warnings are very solid, this warning has seen a lot
of bugs in it's history, and is far from perfect, as is evident.

(But this has been explained in other threads).

> there is any decent way to solve this?

Easily, compile your project as standard C, the language libev was written
in.

Your mail is like "I try to compile libev with my pascal compiler, but it
gives me errors, how do I resolve that?" and the answer is "well, use a C
compiler".

This is so obvious I wonder why it comes up again and again.

-- 
                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