Mailing-List: contact cygwin-help AT sourceware DOT cygnus DOT com; run by ezmlm List-Subscribe: List-Archive: List-Post: List-Help: , Sender: cygwin-owner AT sources DOT redhat DOT com Delivered-To: mailing list cygwin AT sources DOT redhat DOT com Message-Id: <200008180013.RAA07740@aleph.ssd.hal.com> Subject: Re: B 20: Post incrementers in arrays as function arguments To: bjball AT sep DOT com (Brian J Ball) Date: Thu, 17 Aug 2000 17:13:49 -0700 (PDT) Cc: cygwin AT sourceware DOT cygnus DOT com (Cygwin Mailing List) In-Reply-To: from "Brian J Ball" at Aug 17, 2000 05:06:53 PM From: "J. J. Farrell" X-Mailer: ELM [version 2.5 PL2] MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit > From: "Brian J Ball" > > This code has produced 3 different results on 4 systems. I don't know what language this code is supposed to be in, so I'll assume it's C89. > #include > int i; > void do_increment(int array[]){ > for(i;i<10;){ > array[i++]=i; > } > } > > void print_array(int a, int b, int c){ > printf("%i\t%i\t%i\n",a,b,c); > } > > main(void){ > int array[10]; > i=0; > do_increment(array); > i=0; > /* This use of var++ in a function call is > unpredictable */ > print_array(array[i++],array[i++],array[i++]); > } Not only unpredictable but also undefined. The compiler can choose to refuse to compile this code if it wishes, or it can produce a program which behaves in some arbitrary way, or anything else it feels like doing. > The only workarround is to know how your system behaves or define temp > variables. Correct. The program you give is not valid C89. The best workaround is to re-write it in valid C so its behaviour is predictable on all C compilers. > However, this works on some platforms and could become an error in porting > software. It works on all platforms, by definition, since the platform is allowed to do anything it fancies when it compiles this code! -- Want to unsubscribe from this list? Send a message to cygwin-unsubscribe AT sourceware DOT cygnus DOT com