From owner-freebsd-current Mon Oct 14 01:14:03 1996 Return-Path: owner-current Received: (from root@localhost) by freefall.freebsd.org (8.7.5/8.7.3) id BAA10283 for current-outgoing; Mon, 14 Oct 1996 01:14:03 -0700 (PDT) Received: from zwei.siemens.at (zwei.siemens.at [193.81.246.12]) by freefall.freebsd.org (8.7.5/8.7.3) with ESMTP id BAA10234 for ; Mon, 14 Oct 1996 01:13:12 -0700 (PDT) Received: from sol1.gud.siemens.co.at (root@[10.1.143.100]) by zwei.siemens.at (8.7.5/8.7.3) with SMTP id KAA04205 for ; Mon, 14 Oct 1996 10:11:11 +0200 (MET DST) Received: from ws2301.gud.siemens.co.at by sol1.gud.siemens.co.at with smtp (Smail3.1.28.1 #7 for ) id m0vCi8U-000211C; Mon, 14 Oct 96 10:12 MET DST Received: by ws2301.gud.siemens.co.at (1.37.109.16/1.37) id AA158850742; Mon, 14 Oct 1996 10:12:22 +0200 From: "Hr.Ladavac" Message-Id: <199610140812.AA158850742@ws2301.gud.siemens.co.at> Subject: Re: gcc's bug. please comment To: charnier@xp11.frmug.org (Philippe Charnier) Date: Mon, 14 Oct 1996 10:12:22 +0200 (MESZ) Cc: current@FreeBSD.org In-Reply-To: <199610111905.VAA01615@xp11.frmug.org> from "Philippe Charnier" at Oct 11, 96 09:05:36 pm X-Mailer: ELM [version 2.4 PL24 ME8a] Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: owner-current@FreeBSD.org X-Loop: FreeBSD.org Precedence: bulk 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 > #include > > 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