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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T09:50:06+00:00 2026-05-18T09:50:06+00:00

Is it currently possible to override the structure constructor in Fortran? I have seen

  • 0

Is it currently possible to override the structure constructor in Fortran? I have seen proposed examples like this (such as in the Fortran 2003 spec):

module mymod

  type mytype
    integer :: x
    ! Other stuff
  end type

  interface mytype
    module procedure init_mytype
  end interface

contains
  type(mytype) function init_mytype(i)
    integer, intent(in) :: i
    if(i > 0) then
      init_mytype%x = 1
    else
      init_mytype%x = 2
    end if
  end function
end

program test
  use mymod
  type(mytype) :: x
  x = mytype(0)
end program

This basically generates a heap of errors due to redundant variable names (e.g. Error: DERIVED attribute of ‘mytype’ conflicts with PROCEDURE attribute at (1)). A verbatim copy of the fortran 2003 example generates similar errors. I’ve tried this in gfortran 4.4, ifort 10.1 and 11.1 and they all produce the same errors.

My question: is this just an unimplemented feature of fortran 2003? Or am I implementing this incorrectly?

Edit: I’ve come across a bug report and an announced patch to gfortran regarding this issue. However, I’ve tried using a November build of gcc46 with no luck and similar errors.

Edit 2: The above code appears to work using Intel Fortran 12.1.0.

  • 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-18T09:50:06+00:00Added an answer on May 18, 2026 at 9:50 am

    I consulted my copy of the Fortran 2008 standard. That does allow you to define a generic interface with the same name as a derived type. My compiler (Intel Fortran 11.1) won’t compile the code though so I’m left suspecting (without a copy of the 2003 standard to hand) that this is an as-yet-unimplemented feature of the Fortran 2003 standard.

    Besides that, there is an error in your program. Your function declaration:

      type(mytype) function init_mytype
        integer, intent(in) :: i
    

    specifies the existence and intent of an argument which is not present in the function specification, which should perhaps be rewritten as:

      type(mytype) function init_mytype(i)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm not sure if this is even possible but here goes: Currently I have
I'm developing an application which currently have hundreds of objects created. Is it possible
I'll try to make this as straight forward as possible. Currently our team has
Is it currently possible with pre release of ironruby to run rubygems? It seems
Possible Duplicate: How do I get the HMODULE for the currently executing code? I'm
Is it possible to get the name of the currently logged in user (Windows/Unix)
Is it possible for a .NET application to grab all the window handles currently
Possible Duplicate: How costly is .NET reflection? I am currently in a programming mentality
Lets say I am currently at: http://example.com/folder/page.html Is it possible to create a relative
Is it possible to register a region adapter within a module? I have a

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.