LINUX.IE, website of the Irish Linux Users' Group
Tux rules!

   
Home
New Users
Articles
Download
Projects
Community
Vendors

  Print Version
Email to...
 
Archives:


planetILUG

Recent News

News Archive


Join the
ILUG
on FaceBook


Join the
ILUG
on LinkedIn


Join the
ILUG SETI
Group



















 
 :: Mailing Lists

[ILUG] gcc optimisation weirdness?

[ILUG] gcc optimisation weirdness?

Dave Airlie airlied at parthus.com
Wed May 10 18:00:21 IST 2000



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





More information about the ILUG mailing list
Read this without the formatting.
                                                                                                    

 

Hosted by HEAnet


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!
RSS Version
Powered by Dell