This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: gcc-2.95 OK, gcc-{3,4}.X not OK
- From: Cedric Roux <cedric dot roux at acri-st dot fr>
- To: Andris Kalnozols <andris at hpl dot hp dot com>
- Cc: gcc-help at gcc dot gnu dot org
- Date: Fri, 08 Jan 2010 08:53:54 +0100
- Subject: Re: gcc-2.95 OK, gcc-{3,4}.X not OK
- References: <201001072237.OAA10250@nasdaq.hpl.hp.com>
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.