public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
From: Cedric Roux <cedric.roux@acri-st.fr>
To: Andris Kalnozols <andris@hpl.hp.com>
Cc: gcc-help@gcc.gnu.org
Subject: Re: gcc-2.95 OK, gcc-{3,4}.X not OK
Date: Fri, 08 Jan 2010 07:55:00 -0000	[thread overview]
Message-ID: <4B46E492.8070308@acri-st.fr> (raw)
In-Reply-To: <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.

  reply	other threads:[~2010-01-08  7:55 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <4B3DE0EA.5060302@redhat.com>
2010-01-03  4:55 ` Andris Kalnozols
2010-01-03 11:17   ` Andrew Haley
2010-01-07 22:37     ` Andris Kalnozols
2010-01-08  7:55       ` Cedric Roux [this message]
2010-01-08 10:46       ` Andrew Haley

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4B46E492.8070308@acri-st.fr \
    --to=cedric.roux@acri-st.fr \
    --cc=andris@hpl.hp.com \
    --cc=gcc-help@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).