Book contents
- Frontmatter
- Contents
- Source Code Listings
- Preface
- 1 Introduction
- 2 General Principles
- 3 Formatting Conventions
- 4 Naming Conventions
- 5 Documentation Conventions
- 6 Programming Principles
- 7 Programming Conventions
- 8 Input and Output
- 9 Packaging Conventions
- 10 Generic Programming
- 11 Object Orientation
- 12 Parallel Processing
- 13 Numerical Types, Kinds, and Operations
- 14 C Interoperability
- 15 Updating Old Programs
- A Source Code
- B Rule List
- Bibliography
- Index
14 - C Interoperability
Published online by Cambridge University Press: 05 December 2011
- Frontmatter
- Contents
- Source Code Listings
- Preface
- 1 Introduction
- 2 General Principles
- 3 Formatting Conventions
- 4 Naming Conventions
- 5 Documentation Conventions
- 6 Programming Principles
- 7 Programming Conventions
- 8 Input and Output
- 9 Packaging Conventions
- 10 Generic Programming
- 11 Object Orientation
- 12 Parallel Processing
- 13 Numerical Types, Kinds, and Operations
- 14 C Interoperability
- 15 Updating Old Programs
- A Source Code
- B Rule List
- Bibliography
- Index
Summary
Use Fortran's C interoperability capabilities to interact with C programs.
Due to the enormous popularity of the C programming language (References [46], [38], and [28]), many Fortran programmers need to be able call routines written in C, or written to conform to C calling conventions. Likewise, it is often useful for C programmers to call routines written in Fortran. Beginning with Fortran 2003, there is a new and standard mechanism to allow easier and more portable interfacing between Fortran and C.
Here are some of the topics that must be considered when code written in Fortran accesses that written in C and vice versa:
The mapping of built-in data types between Fortran and C.
The mapping of pointers.
The mapping between Fortran derived types and C structs.
The mapping of global variables.
The internal calling sequence mechanisms for passing actual arguments and function return values during procedure calls.
The mapping of external names between Fortran and C and invocation of functions and procedures.
The next sections present details of these various points. The first deals with the mapping of the basic data types. Using these types, the second section presents the calling mechanism between the two, including mapping of external names; we present a short example. The sections that follow continue presenting the mapping of other types of entities, pointers, global data, and so on, also with short examples.
- Type
- Chapter
- Information
- Modern FortranStyle and Usage, pp. 262 - 270Publisher: Cambridge University PressPrint publication year: 2011