From: Dave Airlie (airlied at domain parthus.com)
Date: Wed 10 May 2000 - 18:00:21 IST
On Wed, 10 May 2000, Kenn Humborg wrote:
> > gcc seems to do weird things to the following:
> >
> > int input, frequency[9];
> >
> > //frequency[] initialised to 0.
> >
> > do {
> > scanf("%d", &input);
> > if (input > 0 && input < 11) {
> > //point 1
> > (frequency[input-1])++;
> > //point 2
> > }
> > } while (input);
> >
> > if i compile with -O2 or -O3 it works as i expect it to, but if i compile
> > with "gcc -o test test.c" then:
> >
> > it works correctly for digits 0 thru 9, however if i enter 10 it goes
> > wrong: at point 1 input == 10, at point 2 input == 11!
>
How are you testing your theory printf or debugger??
I haven't looked at it but if you are using a debugger, registers might be
causing trouble, it could be storing input in a register but overwriting
it with the values from increment ..
Not sure .. look at the assembler output from gcc ... (gcc -S or -s or
someat)..
Dave.
--
David Airlie, Software Engineer
Parthus Technologies plc., Mary Rosse Centre, National Tech Park, Limerick.
t: +353-61-508116 / f: +353-61-508101 / David.Airlie at domain parthus.com
This archive was generated by hypermail 2.1.6 : Thu 06 Feb 2003 - 13:06:05 GMT