How To Get To Fortran Common Variables Within a C Code

  • Thread starter Christopher M. Lusardi
  • Start date
C

Christopher M. Lusardi

Hi,

I know about the convention of appending "_" to c routine names, but
how do I access Fortran global variables in c?

Thank you,
Christopher Lusardi
 
M

Mark A. Odell

(e-mail address removed) (Christopher M. Lusardi) wrote in

I know about the convention of appending "_" to c routine names, but
how do I access Fortran global variables in c?

Sadly, the C language does not specify how to do this (e.g. no help here).
 
D

Derk Gwen

# I know about the convention of appending "_" to c routine names, but
# how do I access Fortran global variables in c?

You need to verify the details with your compiler vendors, but the
general idea is that
common /abc/ x,y,z
real x
integer y
complex z
corresponds to the global variable declaration
struct {
double x;
int y;
struct {double re,im;} z;
} abc;
with details varying with the system and compilers.
 
E

E. Robert Tisdale

Christopher said:
I know about the convention
of appending "_" to [Fortran] routine names,
but how do I access Fortran global variables [from] C?

Fortran 77 does not support "global" variables.
> cat file.f
program main
common/structure/i, x
integer i
real x
end
> g77 -c file.f
> nm file.o
00000000 T MAIN__
U s_stop
00000008 C structure_

The common block named structure is identified by the symbol structure_.
In your C program, define a global variable

struct {
int i;
float x;
} structure_;

so that you can reference the data members of the common block

structure_.i

and

structure_.x
 
C

CBFalconer

E. Robert Tisdale said:
Christopher said:
I know about the convention
of appending "_" to [Fortran] routine names,
but how do I access Fortran global variables [from] C?

Fortran 77 does not support "global" variables.
cat file.f
program main
common/structure/i, x
integer i
real x
end
g77 -c file.f
nm file.o
00000000 T MAIN__
U s_stop
00000008 C structure_

The common block named structure is identified by the symbol
structure_. In your C program, define a global variable

C doesn't have global variables. Get your terms straight.
struct {
int i;
float x;
} structure_;

so that you can reference the data members of the common block

structure_.i

and

structure_.x

Fortran is NOT on topic in c.l.c. Are you doing this just to
avoid having people around who know that language criticize your
statements?

*** WARN WARN WARN ***
Anything Trollsdale posts is usually wrong.
 
G

glen herrmannsfeldt

Christopher M. Lusardi wrote:

I know about the convention of appending "_" to c routine names, but
how do I access Fortran global variables in c?

The actual methods tend to be system dependent, but the
most obvious one is that a COMMON corresponds to an
extern struct.

One complication is that C allows padding and Fortran
does not.

-- glen
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,764
Messages
2,569,564
Members
45,039
Latest member
CasimiraVa

Latest Threads

Top