bug or specification ? (gcc 3.0)
Geoff Keating
geoffk@geoffk.org
Fri Jun 22 10:42:00 GMT 2001
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>
More information about the Gcc-bugs
mailing list