Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

segmentation fault

Status
Not open for further replies.

ranjith1009

Programmer
Aug 13, 2009
4
US
This is a portion of a program i am working on.
-------------------------
write(*,*) psi,t,NOB,pi
qn=IDINT((psi-t)*NOB/(2*pi)+0.5d0)
write(*,*) t,qn
write(*,*) 'line'

-----------------
output for first write statement:
2.0943951023931953 0.0000000000000000 3 3.1415926535897931

output for second write statement:
0.0000000000000000 1

output for third write statement:
line
------------------------
I get the error "Segmentation fault".

The variable qn is not used anywhere else (it was for debugging purpose).

And this error no more appears if i change the statement to:
write(*,*) t,qn+1

Irrespective of whatever exists before and after the portion of the code i pasted above (and error most likely is from outside this-third write executed!), these look quite strange. If anyone has some thoughts, it will be a great occasion for me to learn.

addtl info: using f95 compiler on linux.


Thanks,

Ranjith.
 
Can you just type

g95 --version

Just interested in knowing which version this occurs on because I cannot reproduce it on G95 (GCC 4.0.3 (g95!) Jun 25 2006)
 
The same behaviour as xwb - no error.
I have g95 on Windows (MinGW)
$ g95 --version
G95 (GCC 4.0.4 (g95 0.92!) Oct 14 2008)
 
Thank you. perhaps did not make it clear. The error is (was)outside this block, as in most cases for segmentation fault function argument mismatch (one of the subroutine calls used in the function). but what would like to know is, how can that cause such an error?
 
Hi ranjizh1009
ranjith1009 said:
..perhaps did not make it clear. The error is (was)outside this block..
Please be clear next time and post the relevant part of code.

The segmentation fault can have several causes, e.g when you try to access an array element out of array bounds, such like in example I posted in this thread:

You can try this:

1. Compile your program with these options
Code:
$ g95 your_pgm.f95 -o your_pgm [COLOR=red]-ftrace=full -fbounds-check[/color]
Then g95 gives you a better hint when error occurs.
For the above example, when I compile it with these options and try to run it, I get this message, which says me exactly what's wrong on which line
Code:
At line 7 of file error_array.f95
Traceback: not available, compile with -ftrace=frame or -ftrace=full
Fortran runtime error: Array element out of bounds: 100 in (1:3), dim=1

2. Compile your program with the debug option
Code:
$ g95 your_pgm.f95 -o your_pgm [COLOR=red]-g[/color]
and try to debug it.
Debugging the above example using insight (free debugger) the program stops at the line
Code:
7	a(i) = 3.0 ! This should not be accessed
with the message
Program received signal SIGSEGV, Segmentation Fault
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top