Re: undefined variable problem



Bart Vandewoestyne wrote:
I am a bit confused... I have a module with the following
variable:

integer(kind=i4b), dimension(:,:,:), allocatable, private :: a

Within that module, I have a subroutine that tries to access this
variable using a simple print statement:

print *, a

I am quite sure the variable a is allocated, because if i check
it right before the print statement with the ALLOCATED intrinsic,
it appears to be allocated.

However, when i compile and run my code with the NAGWare f95
compiler Release 5.1(282) on Linux, i get the following error:

Reference to undefined variable A
Program terminated by fatal error

With gfortran and g95 i don't get this error.

I have no clue what is going wrong here... what
are the things I should look for? I refuse to believe that this
is a compiler bug... i guess it is more likely that the problem
is at my side, but i cannot think of what could be wrong...

Thanks,
Bart


What values have you assigned to A?

It's perfectly possible to have something that's both allocated and undefined. If you want it given a value when it's allocated, you have to do so yourself. Some compilers are much pickier about it that others - but it is always an error. At best you get the message you have seen. Next best, at least in the "are you feeling lucky" sense, is that it gets allocated to zero and that's what you wanted. And then there's the third case, where what's in it is random bits from whatever happened to be in the memory being used beforehand.

Catherine.

--
Catherine Rees Lay

Polyhedron Software Ltd. Registered Office: Linden House,
93 High St, Standlake, Witney, OX29 7RH, United Kingdom.
Registered in England No.2541693. Vat Reg No. GB 537 3214 57
.



Relevant Pages

  • Re: Weird problem on Lahey lf95 v6.2b
    ... > I've encountered using the Lahey F95 compiler for Linux. ... > Here, ais a double precision array, and ba default real array; ... > print statement, but in the second and third has been truncated down to ... I think this is non standard conforming and ...
    (comp.lang.fortran)
  • undefined variable problem
    ... I have a subroutine that tries to access this ... it right before the print statement with the ALLOCATED intrinsic, ... compiler Release 5.1on Linux, ... Program terminated by fatal error ...
    (comp.lang.fortran)
  • Re: undefined variable problem
    ... On 30 mrt, 11:59, Bart Vandewoestyne ... I have a subroutine that tries to access this ... it right before the print statement with the ALLOCATED intrinsic, ... compiler Release 5.1on Linux, ...
    (comp.lang.fortran)
  • Re: unexpected error
    ... If you get an exception during the evaluation of the value you are going ... it will never be assigned which is what the compiler is ... print statement) into the try-block after the assignment. ...
    (comp.lang.java.programmer)
  • Re: forcing standard output to overwrite same line
    ... >> I have a lengthy program that has an outer loop, ... >> print statement that tells me what percent complete that loop is. ... > subroutine non_adv ... but, it's not critical to me, so i'm going to stop wasting ...
    (comp.lang.fortran)