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 parthus.com
Maintained by the ILUG website team. The aim of Linux.ie is to
support and help commercial and private users of Linux in Ireland. You can
display ILUG news in your own webpages, read backend
information to find out how. Networking services kindly provided by HEAnet, server kindly donated by
Dell. Linux is a trademark of Linus Torvalds,
used with permission. No penguins were harmed in the production or maintenance
of this highly praised website. Looking for the
Indian Linux Users' Group? Try here. If you've read all this and aren't a lawyer: you should be!