[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

Re: gEDA-user: Problems with PCB



On Thu, 2007-10-25 at 16:56 -0400, DJ Delorie wrote:
> > What is a "type punned pointer", and are we doing anything dangerous with them?
> 
> struct grill x;
> ((struct foo)x).bar = 5;
> or
> struct grill *x;
> ((struct foo *)x)->bar = 5;
> 
> Changing the type of an object on the left side of an assignment has
> become a violation of strict aliasing rules, and newer GCCs use
> aliasing during optimization.  Thus, gcc may not properly realize that
> a value has been overwritten by such an assignment, and use an old
> value instead of the (correct) new value.

Does this imply that all kinds of bad things might be happening, or is
the compiler smart enough to disable these optimisations when it gives
the warning?

I guess it'd have to be specific cases where the old values might be
used, but is there a way to build PCB without the risk?

> What you're supposed to do is use "void *" as your intermediate value,
> not a pointer to some specific type.

((struct foo *)(void *)x)->bar = 5; ?

or do you have to have:
void *x; // at the top to start with?

> > Is there a portable way to printf a size_t?
> 
> Cast it to a long and use %ld is portable enough for us.

Ok, might just be a cast to long which is missing then.


Thanks for the explanation above, I know I didn't "get" it when I tried
to Google search the term last time I looked at these warnings.

-- 
Peter Clifton

Electrical Engineering Division,
Engineering Department,
University of Cambridge,
9, JJ Thomson Avenue,
Cambridge
CB3 0FA

Tel: +44 (0)7729 980173 - (No signal in the lab!)



_______________________________________________
geda-user mailing list
geda-user@xxxxxxxxxxxxxx
http://www.seul.org/cgi-bin/mailman/listinfo/geda-user