[comp.lang.c] Bug in Microsoft C 5.1

mapmef@gdr.bath.ac.uk (M E Fletcher) (09/07/89)

I've trimmed my program down substantially so there's for excuse at not
looking at it now! I already know it's weird and horrible, but that's
because it's from a larger program which has undergone major surgery.


#include <stdio.h>
static unsigned modulo[9]={0,0,0,0,0,0,0,0,0};
main()
{long *timeptr;
 int i;
 unsigned status;
 i=0; while (i!=9)
 {do {status=do_nothing(0,0,0);
      printf("%d\n",i); }
     while (0);
  do {status=do_nothing(0,0,modulo[i]);}
     while (status);
  i++;
 }
}
int do_nothing(a,b,c)
int a,b,c;
{return(0);}

 When I run this instead of printing out 0,1,2,3,4,5 etc. It prints out
0,1,1,1,1,1 etc. I think there is a bug in the compiler I am using :
Micorsoft's 5.1 .  Can anyone confirm/deny/reproduce this?

Matthew Fletcher, University of Bath, England

SMITHJ@ohstpy.mps.ohio-state.edu (09/09/89)

In article <1989Sep7.104322.1210@gdt.bath.ac.uk>, mapmef@gdr.bath.ac.uk (M E Fletcher) writes:
> I've trimmed my program down substantially so there's for excuse at not
> looking at it now! I already know it's weird and horrible, but that's
> because it's from a larger program which has undergone major surgery.
> 
> 
> #include <stdio.h>
> static unsigned modulo[9]={0,0,0,0,0,0,0,0,0};
> main()
> {long *timeptr;
>  int i;
>  unsigned status;
>  i=0; while (i!=9)
>  {do {status=do_nothing(0,0,0);
>       printf("%d\n",i); }
>      while (0);
>   do {status=do_nothing(0,0,modulo[i]);}
>      while (status);
>   i++;
>  }
> }
> int do_nothing(a,b,c)
> int a,b,c;
> {return(0);}
> 
>  When I run this instead of printing out 0,1,2,3,4,5 etc. It prints out
> 0,1,1,1,1,1 etc. I think there is a bug in the compiler I am using :
> Micorsoft's 5.1 .  Can anyone confirm/deny/reproduce this?

I ran this program on a VAX/VMS using the latest version of VAX C and the
corresct sequence of numbers was printed out so that it does appear as tho'
you have located a bug in the MSC 5.1 compiler.

I suggest that you first try rewriting your program (if possible) so that it
looks more ANSI standard with regards to function calls:
	use 		function(type var,...)
			{
			/* ... */
			}
	instead of	function(var,...)
			type var,..
			{
			/* ... */
			}
I would also suggest changing the init/while constructs you use to 'for' loops.
While these may seem like silly suggestions you would be suprized how quickly
bugs disappear.

I have rewritten your fragment using my suggestions:

#include <stdio.h>

int main(void);
int do_nothing(int a,int b,int c);

static unsigned modulo[9]={0,0,0,0,0,0,0,0,0};

int main(void)
{
    long     *timeptr;
    int      i;
    unsigned status;
 
    for (i = 0; i != 9; ++i)
    {
	do 
	{
	    status = do_nothing(0,0,0);
      	    printf("%d\n",i); 
	} while (0);
  	do 
	{
	    status = do_nothing(0,0,modulo[i]);
	} while (status);
    }
}

int do_nothing(int a,int b,int c)
{
    return(0);
}
 
-- 
They have one big advantage over us: 
		*they* know where they're going.
Has your family tried 'em, Powdermilk?

/* Jeffery G. Smith, BS-RHIT (AKA Doc. Insomnia, WMHD-FM)       *
 *    The Ohio State University, Graduate Physics Program       *
 *        3193 Smith Lab, Columbus, OH 43210  (614) 292-5321    *
 *    smithj@ohstpy.mps.ohio-state.edu                          */

karl@haddock.ima.isc.com (Karl Heuer) (09/09/89)

In article <4199@ohstpy.mps.ohio-state.edu> SMITHJ@ohstpy.mps.ohio-state.edu writes:
>I ran this program on a VAX/VMS using the latest version of VAX C and the
>corresct sequence of numbers was printed out so that it does appear as tho'
>you have located a bug in the MSC 5.1 compiler.

I'm sure you already know this, but I'd like to point out that "It works on a
VAX" is not a very good test of code correctness.

>I would also suggest changing the init/while constructs you use to 'for'
>loops.  While these may seem like silly suggestions you would be suprized how
>quickly bugs disappear.

It depends on what the goal is.  I assume that at this point he just wants
someone to confirm that it's a real bug (which seems to be the case) so he can
report it to the vendor.  And even if the goal is to get the original program
working, and if it happens that converting from `while' to `for' makes this
manifestation of the bug disappear, I still wouldn't trust the compiler unless
I knew *why* it makes the symptoms go away -- i.e. what constructs tickle it,
and which ones are believed to be safe.

To the original poster: with the program being this simple and still failing,
if possible you should try single-stepping it with a debugger while examining
the contents of `i' at each step.  Or get the compiler to produce a machine-
language listing, and see if you can spot the improperly generated code.

Karl W. Z. Heuer (ima!haddock!karl or karl@haddock.isc.com), The Walking Lint

swh@hpcupt1.HP.COM (Steve Harrold) (09/09/89)

Re: MSC 5.1 bug?

Funny, when I compile the thing under Microsoft C 5.1, it works as 
it's supposed to!!!

Have you corrupted your compiler files somehow?

ly@prism.TMC.COM (09/09/89)

/* Written  6:43 am  Sep  7, 1989 by mapmef@gdr.UUCP in prism:comp.lang.c */
/* ---------- "Bug in Microsoft C 5.1" ---------- */

 When I run this instead of printing out 0,1,2,3,4,5 etc. It prints out
0,1,1,1,1,1 etc. I think there is a bug in the compiler I am using :
Micorsoft's 5.1 .  Can anyone confirm/deny/reproduce this?

Matthew Fletcher, University of Bath, England
/* End of text from prism:comp.lang.c */

	I compiled and ran your program using Microsoft 5.1. The output is 0,
	1, 2, 3, etc.