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?

Burke, Gary : GIG IS&T Gary.Burke at guinness.com
Thu May 11 13:51:41 IST 2000


]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);

Hmmm.  int frequency[9]; give you elements 0 -> 8 inclusive.  If input=10,
then you are trying to access frequency[10-1], or frequency[9], which is not
part of your array.  What seems to be happening is that 'input' is being
places in memory where frequency[9] would be, if it existed.  Hence,
'frequency[9]++' is basically being a 'input++', in this case.

Please note that by accessing an array out of bounds, you are in unknown
territory.  Different compilers, and different options, will do things
differently.  There is generally no way to know what you might be accessing.



Gary
**********************************************************************
This e-mail and any attachment contains information which is private
and confidential and is intended for the addressee only.
If you are not an addressee, you are not authorised to read, copy or 
use the e-mail or any attachment.  
If you have received this e-mail in error, please notify the sender 
by return e-mail and then destroy it.
**********************************************************************




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