gcc-2.95 OK, gcc-{3,4}.X not OK

Cedric Roux cedric.roux@acri-st.fr
Fri Jan 8 07:55:00 GMT 2010


Andris Kalnozols wrote:
> There are no coding nor compilation errors with either
> 
>   pcptr = pcptr->code = nop;
>     or
>   pcptr->code = pcptr = nop;
> 
> As long as the pointers are actually pointing to something,
> this is typical linked list processing.

Well, this is debatable.
If by:
   pcptr->code = pcptr = nop;
you mean:
   pcptr = nop;
   pcptr->code = nop;
(assuming nop == NULL)
then in the second assignment pcptr is NULL,
you dereference a NULL pointer. (And you're
lucky you get a segmentation fault, on some
architectures you have no crash at all and
left with a funky bug.)

>         pcptr->code = fnc_A();

What does that mean in your head?
fnc_A modifies pcptr, so you expect
pcptr in pcptr->code to be the value
before the call or after?

In a hypothetical assembly language, your statement could be:

   load  (pcptr), reg1
   add   #offset(code in PC), reg1
   call  fnc_A
   store regret, (reg1)

Or do you expect:

   call  fnc_A
   load  (pcptr), reg1
   add   #offset(code in PC), reg1
   store regret, (reg1)

This is quite different. I don't know what gcc does, but
I know your pattern is weird and I guess you
should avoid it in production code. It will
give some headaches to those who will need
to maintain the code.

Cédric.



More information about the Gcc-help mailing list