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 8981367
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T20:19:07+00:00 2026-06-15T20:19:07+00:00

My intended use is program main use mod external sub call sub end program

  • 0

My intended use is

program main
  use mod

  external sub

  call sub
end program main

subroutine sub
  ! code here calls subroutines in mod
end subroutine sub

Specifically, will module mod be in scope in subroutine sub? Also, I’d be interested to know more generally when a module is in/out of scope. I’m using gfortran 4.6.1, if it matters.

  • 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-15T20:19:08+00:00Added an answer on June 15, 2026 at 8:19 pm

    It is not in scope of subroutine sub, as sub cannot call routines or use variables from mod, because sub is not part of the program main. They have nothing in common, are separate compilation units and only may call each other (if they are callable).

    Consider this:

    program main
    
      external sub
    
      call sub
    end program main
    
    subroutine sub
      use mod
      ! code here calls subroutines in mod
    end subroutine sub
    

    Here, you can use variables and routines from mod in sub, because sub explicitly uses mod.

    Another example, where sub is an internal procedure of main:

    program main
      use mod
    
      call sub
    
      contains
    
        subroutine sub
          ! code here calls subroutines in mod
        end subroutine sub
    
    end program main
    

    Also in this case you can use things from mod in sub because everything from main is in scope in sub.

    Finally, in this case mod is not in scope, it is similar to the original case.

    program main
      use mod
      use mod2
    
      call sub
    end program main
    
    module mod2
    
      contains
    
        subroutine sub
    
          ! code here calls subroutines in mod
        end subroutine sub
    
    end module mod2
    

    Another issue is the undefining of module variables, when they go out of scope. Fortran 2008 solved this by making all module variables implicitly save.

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

Sidebar

Related Questions

My program is intended for multiple projects (clients) use. I am working w/ PHP
I'm trying to use UNIX sockets for inter-thread communication. The program is only intended
What is the intended use of the optional else clause of the try statement?
I'm working on creating a simple website for an exhibition. It's intended to use
I have a class which is intended for immutable use, hence I would like
I intended for this function to call my MVC action method that returns a
When I compile and run my program in Debug mode, everything works as intended.
I have a program that will analyzes source code. It can recursively go through
I have a program which accepts a perl data structure which is intended to
I'm trying to use some code that I wrote on another computer that splits

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.