compiler option for local variables to default to automatic not working 
Author Message
 compiler option for local variables to default to automatic not working

I am using Compaq fortran 6.6.0 and I'm compiling some code into a DLL
which I call from another program.  I have set the compiler option
called /automatic which I expect to cause all local variables to
reinitialize upon each re-entry.  But this does not seem to be
happening.  It's acting more like variable are STATIC between calls.

I want the REAL local variables to all reset to zero.  How is this
done?

Thanks,

Brian



Wed, 18 May 2011 18:22:15 GMT  
 compiler option for local variables to default to automatic not working
Hello,


Quote:
> I have set the compiler option
> called /automatic which I expect to cause all local variables to
> reinitialize upon each re-entry.  But this does not seem to be
> happening.  It's acting more like variable are STATIC between calls.

If you have set an initial value
in the declaration for the valuable,
you have also set the save attribute
which means static.

This is the data-implies-save rule
that was inherited from Fortran 77.
It is impossible to change now without breaking
miles and miles of old code.

Quote:
> I want the REAL local variables to all reset to zero.  How is this
> done?

It is done by writing executable code to do so.

--
Cheers!

Dan Nagle



Wed, 18 May 2011 19:05:19 GMT  
 compiler option for local variables to default to automatic not working

Quote:
> Hello,


> > I have set the compiler option
> > called /automatic which I expect to cause all local variables to
> > reinitialize upon each re-entry.  But this does not seem to be
> > happening.  It's acting more like variable are STATIC between calls.

> If you have set an initial value
> in the declaration for the valuable,
> you have also set the save attribute
> which means static.

> This is the data-implies-save rule
> that was inherited from Fortran 77.
> It is impossible to change now without breaking
> miles and miles of old code.

> > I want the REAL local variables to all reset to zero.  How is this
> > done?

> It is done by writing executable code to do so.

> --
> Cheers!

> Dan Nagle

Thanks for the reply, Dan.

The code is about 30 years old.  I think one mistake was my thinking
that the /automatic compiler option meant that locals got initialized
to zero.  But that's doesn't seem to be the case.

Don't modern day fortran compilers offer a compile time option to
force the initialization of numeric variables to zero?

I also think I now know that the Compaq compiler option to warn about
the use of uninitialized variables does not work for arrays.  And this
seems to be the source of my misery.

This is a numerical analysis code for fluid dynamics.  It runs ok
until a case is run that doesn't converge.  Then after that happens it
fails to converge on all cases - even good ones.  It's because of
invalid values generated and left behind by the failed case.

I know what to do fix it.  I hope I don't mess up anything else.

Brian



Thu, 19 May 2011 01:25:53 GMT  
 compiler option for local variables to default to automatic not working

Quote:

> I have set the compiler option
> called /automatic which I expect to cause all local variables to
> reinitialize upon each re-entry.  But this does not seem to be
> happening.  It's acting more like variable are STATIC between calls.

> I want the REAL local variables to all reset to zero.  How is this
> done?

Your expectation is incorect. That is not what automatic does.

If you want to have a variable reset to zero on each call, the way to do
that is with an assignment statement (i.e. an ordinary old x = 0.) at
the beginning of the procedure. That's what assignment statements do.

No, there isn't a way to do it automatically for all variables.

Some compilers have nonstandard options to initialize all variables to
zero. That is largely considered an option for support of poorly-written
old codes. However, I know of no compilers that even have options to
simillarly reinitialize things on every call. (As I said, no, that's not
what "automatic" does).

If you have existing code that depended on the one-time initiliazation
option and you are trying to turn that code into something that can be
run multiple times in a program, with the initialization happening each
time, then the only solution is to fix the code to not depend on options
like that. I would consider such code to have been broken in the first
place.

Yes, I know it can be a lot of work to go through such a code and find
all the variables that need such treatment. That's particularly so if
the program uses implicit typing, which is also typical of the coding
style that depends on such initialization. I've been there, though it
was a long time ago (nearly 40 years). That is one of the many reasons
why I strongly disrecommend that coding style. See my signature.

--
Richard Maine                    | Good judgment comes from experience;
email: last name at domain . net | experience comes from bad judgment.
domain: summertriangle           |  -- Mark Twain



Thu, 19 May 2011 01:30:07 GMT  
 compiler option for local variables to default to automatic not working
Hello,


Quote:
> Don't modern day fortran compilers offer a compile time option to
> force the initialization of numeric variables to zero?

If so, it's very compiler-specific.
You must check with the individual vendor.
I won't venture a general statement
about how often or under what circumstances
any such option is effective.

--
Cheers!

Dan Nagle



Thu, 19 May 2011 01:57:20 GMT  
 compiler option for local variables to default to automatic not working

Quote:


> > Don't modern day fortran compilers offer a compile time option to
> > force the initialization of numeric variables to zero?

> If so, it's very compiler-specific.

But if you go back and check the original post, you'll see that he was
looking for an option to do this on every call - not just initially. To
my knowledge, the answer to that question is simpler; along the same
vein, but simpler. It is just "no". I know of no Fortran compilers, now
or in the past, that did that. It is at least vaguely possible that I've
overlooked or forgotten one, but I think you'll find that just "no" is
at least a darn good approximation of the answer.

--
Richard Maine                    | Good judgment comes from experience;
email: last name at domain . net | experience comes from bad judgment.
domain: summertriangle           |  -- Mark Twain



Thu, 19 May 2011 02:11:36 GMT  
 compiler option for local variables to default to automatic not working

Quote:

>Some compilers have nonstandard options to initialize all variables to
>zero. That is largely considered an option for support of poorly-written
>old codes. However, I know of no compilers that even have options to
>simillarly reinitialize things on every call. (As I said, no, that's not
>what "automatic" does).

What would be useful, however, would be an option to initialise
everything to a signalling NaN - including for integers and other
types.  Sadly, few compilers offer even an approximation.

Regards,
Nick Maclaren.



Thu, 19 May 2011 02:56:27 GMT  
 compiler option for local variables to default to automatic not working

Quote:
> But if you go back and check the original post, you'll see that he was
> looking for an option to do this on every call - not just initially. To
> my knowledge, the answer to that question is simpler; along the same
> vein, but simpler. It is just "no". I know of no Fortran compilers, now
> or in the past, that did that. It is at least vaguely possible that I've
> overlooked or forgotten one, but I think you'll find that just "no" is
> at least a darn good approximation of the answer.

Which is what the snipped "how often or under what circumstances"
part of my answer was intended to convey to the OP.

I suppose I could have been more clear.

--
Cheers!

Dan Nagle



Thu, 19 May 2011 04:08:28 GMT  
 compiler option for local variables to default to automatic not working
The code has been through many PC based fortran compilers over the
years before getting to me.  I am compiling it into a DLL to use on a
Windows PC instead of an EXE.  So I'll just have to go through it and
fix it.

Thanks for the help, and the very pertinent info on fortran compilers,

Brian



Thu, 19 May 2011 08:05:12 GMT  
 compiler option for local variables to default to automatic not working

Quote:

> The code is about 30 years old.  I think one mistake was my thinking
> that the /automatic compiler option meant that locals got initialized
> to zero.  But that's doesn't seem to be the case.

Definitely not. In fact, with /automatic, variables will have
unpredictable and almost always non-zero values.  If you want zero
initialization, you have to do it yourself.

As Dan noted, you can supply an initial value in the declaration but
that makes the variable non-automatic.  If you do the initialization in
executable code, for example, X=0, then it will happen each time.

Quote:
> Don't modern day fortran compilers offer a compile time option to
> force the initialization of numeric variables to zero?

Some do, yes.  CVF did not.  It's also a "crutch" to support a poor
coding practice.

--

Steve Lionel
Developer Products Division
Intel Corporation
Nashua, NH

For email address, replace "invalid" with "com"

User communities for Intel Software Development Products
   http://software.intel.com/en-us/forums/
Intel Fortran Support
   http://support.intel.com/support/performancetools/fortran
My Fortran blog
   http://www.intel.com/software/drfortran



Thu, 19 May 2011 10:06:15 GMT  
 compiler option for local variables to default to automatic not working

Quote:
> But if you go back and check the original post, you'll see that he was
> looking for an option to do this on every call - not just initially. To
> my knowledge, the answer to that question is simpler; along the same
> vein, but simpler. It is just "no". I know of no Fortran compilers, now
> or in the past, that did that.

Is this the behavior that you describe?

$ cat bar.f90
program main
  call bar
  call bar
end program main

subroutine bar
  real :: a
  print *,a
  a = 2.
end subroutine bar
$ gfortran bar.f90 && ./a.out
 -2.73944461E-05
   2.0000000
$ gfortran -finit-real=nan bar.f90 && ./a.out
             NaN
             NaN



Sun, 22 May 2011 05:40:13 GMT  
 
 [ 21 post ]  Go to page: [1] [2]

 Relevant Pages 

1. HP-UX Fortran compiler option +DA2.0W does not work on my itanium platform

2. local variable and local variable in block behave differently

3. local variables: g77 defaults vs Commercial

4. Local variables in -command .... options

5. automatic variables are not initialized correctly?

6. local variable not found

7. local variable not destructed if the function raised a exception

8. $_SESSION not working on local machine v4.1.2

9. info locals not working as advertised

10. info locals seems not to work properly

11. #!/usr/local/bin/tclsh not working on QNX

12. #!/usr/local/bin/tclsh not working on QNX

 

 
Powered by phpBB® Forum Software