B 20: Post incrementers in arrays as function arguments
Dan Haynes
haynes@anchorgaming.com
Thu Aug 17 15:25:00 GMT 2000
Try using PC Lint to find the bugs in your code.
(hint - array[i++]=i depends on order of evaluation and is totally bogus C
code)
:-)
Dan
> -----Original Message-----
> From: cygwin-owner@sources.redhat.com
> [ mailto:cygwin-owner@sources.redhat.com]On Behalf Of Brian J Ball
> Sent: Thursday, August 17, 2000 4:07 PM
> To: cygwin@sourceware.cygnus.com
> Subject: B 20: Post incrementers in arrays as function arguments
>
>
> This code has produced 3 different results on 4 systems.
> The second result was on the Cygwin B20 system
>
> #include <stdio.h>
> 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++]);
> }
>
> B20 (gcc 2.91.57) on NT 4 output:
> 2 1 0
>
> The only workarround is to know how your system behaves or define temp
> variables. a similar function call was used by a client, and our tests
> showed it failing, since our tester was using VStudio. The
> client was using
> the Tasking complier.
> However, this works on some platforms and could become an error in porting
> software. As to patching... I haven't tried the latest gcc, and I'm not
> versed in compiler theory.
>
> I was not able to find information about this on GNATS or in the cygnus
> mailing list archives.
>
> gcc 2.8.0 on solaris (expected answer)
> 0 1 2
>
> Microsoft Visual Studio 6
> 0 0 0
>
> Our fourth platform was a Tasking compiler for a Seimens micro
> It behaved as we expected (no stdio though).
>
> --
> Brian Ball
> Software Engineer - SEP
> mailto:bjball@sep.com
>
>
> --
> Want to unsubscribe from this list?
> Send a message to cygwin-unsubscribe@sourceware.cygnus.com
>
--
Want to unsubscribe from this list?
Send a message to cygwin-unsubscribe@sourceware.cygnus.com
More information about the Cygwin
mailing list