This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
Re: bug or specification ? (gcc 3.0)
- To: saito at densan dot co dot jp (Hideo Saito)
- Subject: Re: bug or specification ? (gcc 3.0)
- From: Geoff Keating <geoffk at geoffk dot org>
- Date: 22 Jun 2001 10:57:58 -0700
- CC: gcc-bugs at gcc dot gnu dot org
- References: <200106220810.f5M8A9t02018.cygnus.bug-gcc@vw4.densan.co.jp>
saito@densan.co.jp (Hideo Saito) writes:
> To : bug-gcc@gnu.org
> From: saito@densan.co.jp (Hideo Saito)
> Title: bug or specification ? (gcc 3.0)
>
> Hello. I am H.Saito, from Japan. I use NetBSD, mips3 and ELF.
>
> This sss.c program can't execute similarly with gcc-2.95.2.
>
> result of gcc 2.95.2
> 0
> 10
>
> result of gcc 3.0
> 10
> 0
>
> I hope that gcc 3.0 generates same code at NOTICE with gcc 2.95.2.
> Thank you. Good bye.
Unfortunately, it is your program that is in error.
There is no sequence point between the expression 'p' at NOTICE and
the assignment to p in xxx(). Thus, by section 6.5 paragraphs 2 and 3
in the ISO C standard, your program invokes undefined behaviour.
If there was a sequence point there, arguably GCC 3.0's behaviour
would be more correct, as it delays evaluating the left-hand side of
the '=' until the right-hand side is completely evaluated.
> ---sss.c------------------------------------------------------------
> #include <stdio.h>
>
> struct sss {
> int x, y, z;
> } sss0, sss1, *p;
>
> main()
> {
> p = &sss0;
> p->x = xxx(); /* NOTICE */
> printf("%d\n", sss0.x);
> printf("%d\n", sss1.x);
> }
>
> xxx()
> {
> p = &sss1;
> return (10);
> }
--
- Geoffrey Keating <geoffk@geoffk.org>