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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T20:21:38+00:00 2026-06-14T20:21:38+00:00

I am working with both C++ and Fortran code. The C++ code needs to

  • 0

I am working with both C++ and Fortran code. The C++ code needs to call a Fortran subroutine. One parameter of the Fortran subroutine has Fortran type complex.

The C++ code is in one file, and the Fortran code subroutine is in another file. I am using gcc and gfortran on a 64-bit GNU/Linux system.

Here is a snippet showing the Fortran subroutine declaration (and a few additional lines):

SUBROUTINE  minp (AMP,L,L2,FMINP,PHI)
   REAL*4 AMP( L ),FMINP( L )
   COMPLEX PHI( L )

In the C++ file, I understand that arguments passed to the Fortran code need to be passed by reference, and not by value. The Fortran subroutine is declared as a function in the C++ code (at the top of the source code file) using the extern keyword.

extern "C"
{
minp_ (float *amp, int &L, int &L2, float *fminp, complex *phi);

}

However, the last parameter of the function is a complex C array. How might it be possible to:

  1. Allocate memory for a complex array in C/C++ to be passed in as the phi argument?
  2. Pass the array as an argument to the Fortran subroutine in such a way that the memory can be used by the Fortran code?
  • 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-06-14T20:21:39+00:00Added an answer on June 14, 2026 at 8:21 pm

    For interfacing C (and C++ via extern C) and Fortran, I recommend using Fortran’s ISO C Binding. It provides complex types, C_FLOAT_COMPLEX, C_DOUBLE_COMPLEX, and C_LONG_DOUBLE_COMPLEX, to match C’s types. By using the ISO C Binding and writing a Fortran interface declaration to match the C code, you will instruct the Fortran compiler to match the calling conventions of the C compiler. If you use the complex type with the ISO C Binding, dealing with the array won’t be any different from a float/double/long double array. The gfortran manual has examples in the Chapter Mixed-Language Programing and describes the types and intrinsic procedures of the ISO C Binding in the Chapter Intrinsic Modules.

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

Sidebar

Related Questions

I am working with C code functions that call legacy Fortran code subroutines. The
Could someone tell if it's possible to get an OpenCL code working with both
I'm working with backbone and lazy-loading both templates and data for one of my
I'm currently working on a solution which needs to use both Silverlight 3.0 and
I'm working on a php site that needs both Japanese and English. In most
Using PHP5.3.3, I have 2 classes, called SinglePDO and Manager , both working, but
i have one project working greate but in other iphone not working .both are
I am working on both udp/tcp based P2P for file and real time video
I tried both creat and open system call. Both working in the same way
These 2 ways of working both work, but I'm wondering if there's a difference

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.