Re: Does print statement will effect the behavior of program?



Fortran Learner wrote:
....
The problem is, when I try to run that old program, if the lines
start with * are commented, the program will stopped with the
information "forrtl: severe (174): SIGSEGV, segmentation fault
occurred".

But If I drop the * (uncomment the related lines), it will worked. I
am wondering what happened here. And I also found that the program
will stop unless print all the realted varibables.

Here is the related code.

DO 14 I = NCORE+1,NORB
* print *, I, NREF
* print *, IOPTR(I)
* print *, JWLIST(I,IOPTR(I))
IOREF(I,NREF) = JWLIST(I,IOPTR(I))
* print *, "Here no problem"
14 CONTINUE

Some related variables are defined and initialized like this, also the
preset value in the iteration:

NCORE : undefined, but initiaized : NCORE = 0, Present value is:
9
NORB: : undefined, but initiaized : NORB = 0. Present value is:
12
IOPTR(I) : defined in a common block, but NEVER used before the
ieration. ...

This has all the characteristics of out of bounds array access combined
with the possibility of uninitialized variables in either the loop
indices or arrays.

Changing symptoms with the inclusion/exclusion of print statements (or
any other executable code for that matter, it's just so commonly seen w/
i/o owing to the tendency to add debugging statements) is probably one
of the most faq's ever.

I'd suggest compiling with all possible debugging options on,
particularly array bounds checking.

Also, if the code doesn't use implicit none that would be a good start
as well to eliminate all compilation errors arising from its inclusion.

Many codes relied on the nonstandard behavior of some compilers to
initialize variables to zero -- this may also be a case here. While not
a recommendation as to a solution (all variables should definitely be
initialized explicitly), for debugging you might try whatever is the
option for that with the particular compiler you're using.

--
.



Relevant Pages

  • Re: Does print statement will effect the behavior of program?
    ... This has all the characteristics of out of bounds array access combined ... I'd suggest compiling with all possible debugging options on, ... initialize variables to zero -- this may also be a case here. ...
    (comp.lang.fortran)
  • Re: mex compiling error
    ... I have a problem compiling my Mex-Files. ... but I guess there is no time for a C programming cource at the moment... ... So how can I initialize the array at run time? ...
    (comp.soft-sys.matlab)
  • Re: Arraz initialization in ANSI C++
    ... > Class Test { ... compiling with some older compilers), ... question at hand, 2) you cannot initialize (in the "initialization, not ... You can have an actual array (though you do need ...
    (comp.lang.cpp)
  • Re: CASE...OF
    ... an associated array of xt values for the words that handle each case. ... rather than just comparing the values sequentially. ... compiling a CASE statement using IF and ... but I have a word called SpecialCases that checks the XT (CFA in my ...
    (comp.lang.forth)
  • Re: Array Integers vs Array Variables
    ... "Roland Hall" wrote in message ... :>: True, you must use an actual number when dimming an array, because the ... :>: is put in memory with the Dim statement before any variables are ... It doesn't get a value until after all the compiling has ...
    (microsoft.public.inetserver.asp.general)