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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T19:14:44+00:00 2026-05-17T19:14:44+00:00

In Fortran, a clear difference exists between function and subroutine: functions return one value,

  • 0

In Fortran, a clear difference exists between function and subroutine: functions return one value, subroutines return no value. This introduce a cascade of differences between the two. One example is the calling semantics: you can call a function just as in other languages, but in order to call a subroutine you must issue a call statement first.

With the addition of pointers and data types in Fortran95, it appears that there is no technical limitation in making any subprogram a function, and keeping subroutines just for legacy. Functions could return zero (you just return a dummy integer), one, or multiple values (for example, you could return a pointer to an allocated instance of a type, like a C++ STL Pair).

Am I wrong? Do we still need subroutines in Fortran programming due to some feature that subroutines have and functions don’t?

  • 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-05-17T19:14:44+00:00Added an answer on May 17, 2026 at 7:14 pm

    If you search the comp.lang.fortran archives, you’ll find discussions about the semantics of functions. IIRC it turns out that it’s not clearly specified in the standard what is and what isn’t allowed for functions that have side-effects.

    For instance, can the compiler optimize

    x = foo(args) + foo(args)

    into

    x = 2 * foo(args)

    Or for another example, consider

    x = y + foo(y)

    What if foo() changes the value of y? Remember that Fortran doesn’t have the C concept of sequence points.

    In general, the recommendation by several experts is to use functions only if they’re pure, otherwise use subroutines. And, that is advice that I follow myself as well.

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

Sidebar

Related Questions

FORTRAN provides several functions to convert a double precision number to an integral value.
I'm programming in FORTRAN and C on an SGI running Irix 6.5, but this
From time to time I read that Fortran is or can be faster then
I have a line of Fortran code, which includes some text. I'm changing the
I have a piece of fortran code, and I am not sure which standard
I need to start developing in FORTRAN, any recommendations on learning\developing FORTRAN coming from
I've been asked to measure the performance of a fortran program that solves differential
I have a static linkable library of C and Fortran routines compiled and linked
I've recently come to maintain a large amount of scientific calculation-intensive FORTRAN code. I'm
I am trying to call out to a legacy dll compiled from FORTRAN code.

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.