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

  • SEARCH
  • Home
  • 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 6576965
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T15:34:37+00:00 2026-05-25T15:34:37+00:00

Gfortran won’t let me compile the following code because nLines and nIOstts can’t be

  • 0

Gfortran won’t let me compile the following code because nLines and nIOstts can’t be initialized like this; so I had to declare them first and then add two lines to the code to set their required initial values.

Why does this work like this? Perhaps with INTENT(OUT) it makes a little more sense since the variable in which the function will store the data already exists (and I don’t recall right now whether Fortran subroutines worked by reference or not), but for the RESULT variable it would seem rather unnecessary. Is this specific of the compiler or is it a general Fortran characteristic?

FUNCTION LinesInFile(nUnit,nIOstts) RESULT(nLines)

IMPLICIT NONE  
INTEGER,INTENT(IN)  :: nUnit  
INTEGER,INTENT(OUT) :: nIOstts=0  
INTEGER             :: nLines=-1

DO WHILE (nIOstts.EQ.0)  

    READ(UNIT=nUnit,FMT='(A)',nIOstts)
    nLines=nLines+1

ENDDO

END FUNCTION
  • 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-25T15:34:37+00:00Added an answer on May 25, 2026 at 3:34 pm
    
    TYPENAME :: variable = somevalue
    
    

    doesn’t do what you think it does. Namely, this will put an implicit SAVE attribute on the variable, with the initial value somevalue. SAVE doesn’t make sense for procedure arguments, hence it’s not allowed.

    So what you want is

    
    TYPENAME :: variable
    variable = somevalue
    

    which will set the value to somevalue every time when the procedure is executed.

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

Sidebar

Related Questions

I'd like to compile a fortran code with gfortran so that it will work
I'm trying to compile a piece of code with gfortran and it's failing with
I am using gfortran to compile FORTRAN 77 and would like to have DEBUG
I'm getting the following errors trying to compile a project: (fortran, using gfortran) undefined
I understand gfortran can compile f90 or f95? How does it know which one
I'm trying to get some code compiled under gfortran that compiles fine under g77.
I'm trying to return a type from a fortran function. This is the code.
I just managed to get gfortran to compile properly, with Xcode Tools 4.2 installed
Can someone explain me why the following program doesn't work, and how to make
With gcc and gfortran I can generate a list of preprossesor macros defined by

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.