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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T04:03:53+00:00 2026-05-28T04:03:53+00:00

program main real, parameter :: a = 1 !real :: a !a=1 res =

  • 0
program main
   real, parameter :: a = 1 
   !real :: a
   !a=1

   res = func(a)
   write(*,*) res

end program main

function func(a)
   real, parameter :: b=a+1  !(*)
   func = b
   return
end function func

My compiler complains at the line marked (*). Is there a way to set the value of a constant with a value coming outside that 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-28T04:03:54+00:00Added an answer on May 28, 2026 at 4:03 am

    You can’t declare “b” as a parameter since its value is not constant at compile time, since it depends on the function argument.

    It is a good idea to use “implicit none” so that you are sure to declare all variables. Also to place your procedures into a module and “use” that module so that the interface is known to the caller. As in:

    module my_funcs
    implicit none
    contains
    
    function func(a)
       real :: func
       real, intent (in) :: a
       real :: b
       b = a + 1
       func = b
       return
    end function func
    
    end module my_funcs
    
    program main
       use my_funcs
       implicit none
       real, parameter :: a = 1
       real :: res
    
       res = func(a)
       write(*,*) res
    
    end program main
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to write a program with a function which returns a matrix with
Folder with program: C:\ProgramFolder In folder there is a package with classes: com\mysite\my_program Main
C++03 3.6.1.3 : The function main shall not be used (3.2) within a program.
Our main program is in java but the code that extracts our data from
So the main program is in C#. Inserting new records into a VFP database
In the below program: class Main { static string staticVariable = Static Variable; string
I have my main program window, and I would like to make a foldable
Consider this program int main() { float f = 11.22; double d = 44.55;
I'm wondering if it is possible to add methods in main program to an
Please consider the following fork() / SIGCHLD pseudo-code. // main program excerpt for (;;)

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.