Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 14 Oct 1996 10:12:22 +0200 (MESZ)
From:      "Hr.Ladavac" <lada@ws2301.gud.siemens.co.at>
To:        charnier@xp11.frmug.org (Philippe Charnier)
Cc:        current@FreeBSD.org
Subject:   Re: gcc's bug. please comment
Message-ID:  <199610140812.AA158850742@ws2301.gud.siemens.co.at>
In-Reply-To: <199610111905.VAA01615@xp11.frmug.org> from "Philippe Charnier" at Oct 11, 96 09:05:36 pm

next in thread | previous in thread | raw e-mail | index | archive | help
E-mail message from Philippe Charnier contained:
> 
> Hello,
> 
> A friend found a bug in gcc-2.7.2.1. The following program fails on
> i386 architecture (both FreeBSD and solaris-x86) and works as expected
> on sparc (both sunos and solaris2.5.1) and on hp (hp-ux9.07). As I'm
> not on the gcc-bug list, please comment before I report the bug. This
> afternoon I sent a bug report to Sun but it was before trying on
> FreeBSD.
> 
> The output should be `1 2' but it is `2 1' on i386 computers.
> Here is the code:
> 
> ----------mypb2.c-----------------
> #include <stdio.h>
> #include <stdlib.h>
> 
> main()
> { FILE *fic;
>   int a[2][50], i = 0;
> 
>   fic=fopen("mypb2.csv","r");
>   fscanf(fic, "%d;%d", &a[1][i++], &a[1][i++]);
                               ^^^         ^^^
			       Undefined 
			       Behaviour; see comp.lang.c FAQ
>   i = 0;
>   while (i < 2) printf("%d ", a[1][i++]);
>   printf("\n");
>   fclose(fic);
> }

Since you just invoked undefined behavior of the C compiler you should
count yourself happy that your disks weren't wiped off clean.

Specifically, comma in the argument list *is*not*a*sequence*point* and
you cannot tell what the value of i is going to be in those two
references.  The compiler is free to optimize it the way it likes it.
As a matter of fact, you cannot tell what should i be even after this 
line.  What you wrote is just another instance of the well-known:

	i = i++;

/Marino




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199610140812.AA158850742>