nmn wrote: |
---|
HTH,
I am running eclipse indigo on ubuntu 12.04.
G++ compiler didn't give any warning, but crash when run. |
TheIdeasMan wrote: |
---|
HTH means "Hope This Helps", not my initials 8+D (Big smiley face with glasses). There are others like IMO - "In My Opinion", and AFAIK - "As Far As I Know" |
If you would like to direct your comments to someone then use @ and their user tag as in @
TheIdeasMan
Now for your compiler (you didn't say which version of gcc 4.8.1 is the latest):
Set The Warnings to a high level, I routinely use at least these flags :
g++ -std=gnu++11 -Wall -Wextra -pedantic
The gnu++ enables the gnu c++ extensions, can also use -std=c++11.
-Wall turns on a lot of warnings but not all of them cryptically.
-Wextra turns on more warnings not enabled by -Wall.
-pedantic turns on even more warnings.
You can also use -Werror which upgrades warnings to errors, and -pedantic-errors, which does the same for pedantic warnings.
It's all in the documentation - in the shell type
man gcc
there are a zillion options but it's worth reading what they mean.
I use KDevelop or QtCreator as my IDE, depending on what I am doing. KDevelop is a mature application which a lot of good features IMO. I use QtCreator if I want to do a GUI app, and this has a fabulous amount of features & technologies it can use, and can cross compile for different OS's.
nmn wrote: |
---|
then I do this:
a=4, b=8
if I loop through this range (4,8)...
1 2
|
for(int x = a; x<b; x++){
A[x] = 0; // should it be out of bound when x = 5 ?
|
|
Yes, that was what I was saying, and is the reason for your problem, because valid subscripts are 0,1,2,3,4 when you declare A[5].
You could also investigate using a debugger - this is by far the easiest way to diagnose runtime errors. You can step through the code 1 line at a time, keep an eye on the value of the variables & deduce where it all goes wrong.
Your IDE should hopefully have a GUI interface to the debugger.
Hope all goes well.