Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > Fortran > local variable ...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 1 of 10 Topic 8171 of 8551
Post > Topic >>

local variable initilization

by Mike <SulfateIon@[EMAIL PROTECTED] > Apr 23, 2008 at 08:37 PM

Hi

module A
contains
subroutine subA()
real :: x
print *,'before adding',x
x=x+1
print *,'after adding',x
end subroutine subA
end module A
program main
use A
x=100.
call subA()
print *,'first output in main:',x
call subA()
print *,'second output in main:',x
end program main

The results are (CVF6.6c used):
before adding 0
after adding 1
first output in main: 100
before adding 1   <=== why?
after adding 2
second output in main: 100

Why?  Isn't x in subA a local variable?  I read the Chapman's book,
which shows "the values of all the local variables and arrays in a
procedure become undefined whenever we exit the procedure."  I thought
x=0.  x doesn't have SAVE attribute in subA.

Mike
 




 10 Posts in Topic:
local variable initilization
Mike <SulfateIon@[EMAI  2008-04-23 20:37:45 
Re: local variable initilization
"jamesgiles@[EMAIL P  2008-04-23 20:56:08 
Re: local variable initilization
"James Van Buskirk&q  2008-04-23 22:56:59 
Re: local variable initilization
Herman D. Knoble <Skip  2008-04-24 07:29:19 
Re: local variable initilization
blitheli <blitheli@[EM  2008-04-24 06:06:32 
Re: local variable initilization
Dick Hendrickson <dick  2008-04-24 14:17:13 
Re: local variable initilization
"James Van Buskirk&q  2008-04-24 11:39:33 
Re: local variable initilization
Steve Lionel <Steve.Li  2008-04-24 15:08:36 
Re: local variable initilization
=?GB2312?B?SmFuIFZvcmJyqL  2008-04-25 16:42:21 
Re: local variable initilization
Mike <SulfateIon@[EMAI  2008-04-24 21:27:25 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Fri Jul 25 22:34:45 CDT 2008.