This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

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


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.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]