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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T01:20:23+00:00 2026-06-09T01:20:23+00:00

I have a program that consists of mostly Fortran 77 with a C++ wrapper

  • 0

I have a program that consists of mostly Fortran 77 with a C++ wrapper that reads and writes to a database. The two parts of the application share data by uses a feature that if you use a global C/C++ struct named like a Fortran common block. I’m pretty sure this aliasing approach to C++/Fortran integration 1) works for many compiler suites, 2) is *not8 standard. I try to maintain my code so that it uses standard components as much as I can. Also, this integration has proven to be brittle.

In utd.h:

/*************************************************************
 *  This struct must follow the common block points.
 *  See the Fortran include file points.i
 *************************************************************/
typedef struct ALIGN points
{
    double  point[3][MAX_PTS];
    double  edge[3][MAX_PTS];
    double  edgenorm[3][MAX_PTS];
    double  edgerho[MAX_PTS];
    int     nfacets[MAX_PTS];
    double  facet1[3][MAX_PTS];
    double  facet2[3][MAX_PTS];
    double  gaussk[MAX_PTS];
    int     sbstin[MAX_PTS];
    int     coatin[MAX_PTS];
    int     sbstout[MAX_PTS];
    int     coatout[MAX_PTS];
    int     ncorners[MAX_PTS];
    double  cnrpoint[3][MAX_CNRS][MAX_PTS];
    int     ncnredgs[MAX_CNRS][MAX_PTS];
    double  cnredge[3][MAX_CNREDS][MAX_CNRS][MAX_PTS];
    int     cnrsbst[MAX_CNREDS][MAX_CNRS][MAX_PTS];
    int     cnrcoat[MAX_CNREDS][MAX_CNRS][MAX_PTS];
    int     npoints;
} POINTS;

extern POINTS  points_;

In utd.cpp:

POINTS  points_;

In points.i:

  !  maxpnt  -  maximum number of points in a path.
  integer  maxpnt
  parameter ( maxpnt = 1000 )

  integer npoints, nfacets(maxpnt)
  integer ncorners(maxpnt), ncnredgs(maxpnt,maxcorners)
  integer sbstin(maxpnt), coatin(maxpnt)
  integer sbstout(maxpnt), coatout(maxpnt)
  double precision point(maxpnt,3)
  double precision edge(maxpnt,3), edgenorm(maxpnt,3)
  double precision edgerho(maxpnt)
  double precision facet1(maxpnt,3), facet2(maxpnt,3)
  double precision gaussk(maxpnt), cnrpoint(maxpnt,maxcorners,3)
  double precision cnredge(maxpnt,maxcorners,maxcnredges,3)
  integer cnrsbst(maxpnt,maxcorners,maxcnredges)
  integer cnrcoat(maxpnt,maxcorners,maxcnredges)

  common /points/ point, edge, edgenorm, edgerho,
 *                nfacets, facet1, facet2, gaussk,
 *                sbstin, coatin, sbstout, coatout,
 *                ncorners, cnrpoint, ncnredgs,
 *                cnredge, cnrsbst, cnrcoat,
 *                npoints

Is there a better way? I might like to convert the common blocks to modules. Then I’m sure this business of aliasing a common block with a global struct is out the window. How you you construct a Fortran module from C++? How do you read data from such a module?

What is your advice about C++/Fortran integration?

  • 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-09T01:20:24+00:00Added an answer on June 9, 2026 at 1:20 am

    The ISO C Binding of Fortran 2003 makes interoperability of C and Fortran part of the Fortran language standard, and therefore compiler and platform portable. If you only use features of C, most likely it will work in C++, though perhaps that is not absolutely guaranteed. You can mix Fortran 2003 and FORTRAN 77, either within a source file or by mixing routines written in the two versions of the languages. The ISO C Binding supports structures and module variables as global variables, so it can accomplish your goals. Both of these are shown in the Mixed Language Programming Chapter of the gfortran manual. (The ISO C Binding is not specific to gfortran, I’m citing that as a good document.)

    Common blocks are also supported, but I agree with you, best avoided … common blocks add on FORTRAN storage sequence and layout, which is unnecessary. I don’t see any way around manually maintaining the C and Fortran “structures” to have equivalent declarations. If that is the reason for the brittleness you will just have to be careful (baring writing a program to write both from common instructions). One approach that would make it a little easier would be not to put the variables into a structure … then getting a new variable wrong is less likely to effect the older variables and that might make noticing or debugging a mistake easier.

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

Sidebar

Related Questions

I have to develop one program that consists data manipulation (retrieve data, update data
THIS IS HOMEWORK: I have a program that consists of two winforms and three
I have a very small c++ program that consists of two files: main.cpp and
I have a program that consists of two programs: Updater and WorkMaker. Whenever there
Suppose I have a big program that consists of hundreds of methods in it.
I have a program that reads from a file that grabs 4 bytes from
I have an x86 Windows application that consists of a couple of services and
I am working on a program which consists of two parts Service component will
I have a QBASIC program that basically consists of formulas and constants, and I
Assume we have a trivial Java program that consists of just one class: public

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.