From nobody@FreeBSD.org  Wed Dec 27 16:39:15 2000
Return-Path: <nobody@FreeBSD.org>
Received: from freefall.freebsd.org (freefall.FreeBSD.org [216.136.204.21])
	by hub.freebsd.org (Postfix) with ESMTP id 0E1D737B402
	for <freebsd-gnats-submit@FreeBSD.org>; Wed, 27 Dec 2000 16:39:15 -0800 (PST)
Received: (from nobody@localhost)
	by freefall.freebsd.org (8.11.1/8.11.1) id eBS0dEs68194;
	Wed, 27 Dec 2000 16:39:15 -0800 (PST)
	(envelope-from nobody)
Message-Id: <200012280039.eBS0dEs68194@freefall.freebsd.org>
Date: Wed, 27 Dec 2000 16:39:15 -0800 (PST)
From: rumseyj@quorum.co.nz
Sender: nobody@FreeBSD.org
To: freebsd-gnats-submit@FreeBSD.org
Subject: gcc printf prints list of array elements in reverse order
X-Send-Pr-Version: www-1.0

>Number:         23897
>Category:       gnu
>Synopsis:       gcc printf prints list of array elements in reverse order
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-bugs
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Wed Dec 27 16:40:01 PST 2000
>Closed-Date:    Wed Dec 27 18:02:26 PST 2000
>Last-Modified:  Wed Dec 27 18:06:43 PST 2000
>Originator:     John Rumsey
>Release:        FreeBSD 4.2-BETA #1: Mon Nov 20 20:07:38 NZDT 2000
>Organization:
Quorum Computing Limited
>Environment:
FreeBSD jr.quorum.co.nz 4.2-BETA FreeBSD 4.2-BETA #1: Mon Nov 20 20:07:38 NZDT 2000     root@jr.quorum.co.nz:/usr/src/sys/compile/JR  i386

>Description:
printf("%d %d %d %d\n",a[i++],a[i++],a[i++],a[i++])
 prints array elements in reverse order

Occurs on 4.2-BETA: cc -v gives gcc version 2.95.2 19991024 (release)

Also occurs on 3.4-RELEASE: cc -v gives gcc version 2.7.2.3
>How-To-Repeat:
Sample program:

#include <stdio.h>

int a[] = {1,2,3,4};

int main( int argc, char **argv ) {
  int i;

  i = 0;    /* reverse order */
  printf( "%d %d %d %d\n", a[i++], a[i++], a[i++], a[i++] );

  i = 0;    /* correct order */
  printf( "%d ",  a[i++] );
  printf( "%d ",  a[i++] );
  printf( "%d ",  a[i++] );
  printf( "%d\n", a[i++] );
}

>Fix:


>Release-Note:
>Audit-Trail:
State-Changed-From-To: open->closed 
State-Changed-By: nectar 
State-Changed-When: Wed Dec 27 18:02:26 PST 2000 
State-Changed-Why:  
The order of evaluation for arguments to functions is undefined 
by Standard C.   Your example is a programming error. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=23897 
>Unformatted:
