From owner-freebsd-current Fri Oct 11 20:20:19 1996 Return-Path: owner-current Received: (from root@localhost) by freefall.freebsd.org (8.7.5/8.7.3) id UAA19892 for current-outgoing; Fri, 11 Oct 1996 20:20:19 -0700 (PDT) Received: from genesis.atrad.adelaide.edu.au (genesis.atrad.adelaide.edu.au [129.127.96.120]) by freefall.freebsd.org (8.7.5/8.7.3) with ESMTP id UAA19883 for ; Fri, 11 Oct 1996 20:20:14 -0700 (PDT) Received: from msmith@localhost by genesis.atrad.adelaide.edu.au (8.6.12/8.6.9) id MAA03815; Sat, 12 Oct 1996 12:50:03 +0930 From: Michael Smith Message-Id: <199610120320.MAA03815@genesis.atrad.adelaide.edu.au> Subject: Re: gcc's bug. please comment To: charnier@xp11.frmug.org (Philippe Charnier) Date: Sat, 12 Oct 1996 12:50:02 +0930 (CST) Cc: current@FreeBSD.org In-Reply-To: <199610111905.VAA01615@xp11.frmug.org> from "Philippe Charnier" at Oct 11, 96 09:05:36 pm 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 Philippe Charnier stands accused of saying: > > 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++]); Arguments to C functions are usually stacked right-to-left (this is the only way to make functions with variable numbers of arguments work sensibly)(1). Thus, the args to fscanf are evaluated right-to-left, and thus your code is working as one might expect. I would imagine that the Sun and HP compilers calculate the a indices before stacking them for the call, and thus evaluate left-to-right. To me, this implies pedantic metrics-and-clockwatching compiler design, or possibly one or more large customers with large legacy codebases which depend upon code like the snippet above. The C standard _explicitly_ forbids you from making any assumptions about the order of evaluation of function arguments, so the bug is yours. (1) Yes, I know there are other ways of doing it. No, none of them work sensibly. -- ]] Mike Smith, Software Engineer msmith@atrad.adelaide.edu.au [[ ]] Genesis Software genesis@atrad.adelaide.edu.au [[ ]] High-speed data acquisition and (GSM mobile) 0411-222-496 [[ ]] realtime instrument control (ph/fax) +61-8-267-3039 [[ ]] Collector of old Unix hardware. "Where are your PEZ?" The Tick [[