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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T10:20:06+00:00 2026-05-30T10:20:06+00:00

I am Fortran beginner and I am trying to adopt some ifort code for

  • 0

I am Fortran beginner and I am trying to adopt some ifort code for compilation with gfortran.

I have problem with the c_loc() function, which in ifort seems to accept dynamic arrays but with gfortran compilation stops with error:

Error: Argument ‘septr1’ to ‘c_loc’ at (1) must be an associated scalar POINTER

So does anyone knows how to adapt the following ifort code for compilation with gfortran?

integer(c_int), dimension(:), pointer  :: septr1=>null()
type(c_PTR) :: septr

allocate (septr1(10))
septr1 = 33
septr = c_loc(septr1)
  • 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-30T10:20:08+00:00Added an answer on May 30, 2026 at 10:20 am

    This appears to be a requirement from the old Fortran 2003 and relaxed in Fortran 2008. More recent gfortran (5+) accepts this.


    You can get the location of the start of the array, the value with offset 0 in C.

    septr = c_loc(septr1(1))
    

    or generally not 1 but lbound(septr1).

    See the requirements for c_loc argument in Metcalf, Reid and Cohen or in Fortran standard.


    It is generally much better to pass the array by reference in normal Fortran way and not to construct an explicit c pointer. For example:

     call some_c_function(n,A)
    

    where some_c_function has Fortran interface

     interface
      subroutine some_c_function(n,A) bind(C)
       use iso_c_binding,only: c_int,c_float    !you can use also import here
    
       integer(c_int),value      :: n
       real(c_float),dimension(n):: A
      end subroutine some_c_function
     end interface
    

    for C prototype

     void some_c_function(int n, float* A)  //(hope so, I am not so good in C).
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a line of Fortran code, which includes some text. I'm changing the
I have some old fortran 77 I'm trying to port to gcc on Windows.
I have the following FORTRAN code which I need to convert to C or
I have a Fortran program, which I can compile using f77, f95 or ifort
I have some Fortran 77 source files that I'm trying to convert from a
I have a piece of fortran code, and I am not sure which standard
I have a Fortran module which I am trying to compile with f2py (listed
I have a fortran (unmanaged code) dll as the calculation engine, and a C#
I have a FORTRAN 95 program that needs to make some calls to the
I very rarely use fortran, however I have been tasked with taking legacy 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.