Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9206917
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T00:16:42+00:00 2026-06-18T00:16:42+00:00

If I initialize a variable in a Fortran declaration statement, that variable implicitly receives

  • 0

If I initialize a variable in a Fortran declaration statement, that variable implicitly receives a SAVE attribute and the initialization expression will only be executed once.

For example, the following program

program test
implicit none

    call foo()
    call foo()

contains

    subroutine foo ()
        integer :: i = 0

        i = i + 1
        write(*,*) i
    end subroutine foo
 end program test

will print

1
2

Since this is different in many other languages I was wondering why the Fortran standard committee chose this behavior?

Thanks a lot!
Mike

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T00:16:43+00:00Added an answer on June 18, 2026 at 12:16 am

    This is mainly due to historical reasons. Old compilers (Fortran IV(66) and before) were implemented to produce programs using mainly static memory. Old machines even didn’t have any stack. Therefore the programs behave, as the variables were defined as save.

    The predecessor of the variable initialization, the DATA statement, is more like defining an initial content of static memory (similar to the directives for the data segment in assembly), than the on call variable initialization you may know from C. The syntax became similar to the C variant later.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a class. I initialize a variable in the constructor of that class.
In C++ you can initialize a variable in an if statement, like so: if
How do I default-initialize a local variable of primitive type in C++? For example
I have to initialize a script variable in a for loop with different values
Does anyone know why a library initialized within dlopen() would initialize a static variable
I want to initialize a static Class variable in Java: public class NumberExpression {
When we create a variable and don't initialize it, then some (random) number called
I am trying to use a C++11 Lambda to initialize a const member variable
Can I create a Bash script with persistent variable-values? For example, I initialize a
It is a best practise to initialise a variable at the time of declaration.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.