Book contents
- Frontmatter
- Contents
- Foreword
- Preface
- 1 Introduction to Modern Fortran
- 2 Array-Valued Functions
- 3 Mathematical Abstractions
- 4 Memory Management
- 5 An Interface Problem
- 6 Interfacing to C: SQLite As an Example
- 7 Graphics, GUIs, and the Internet
- 8 Unit Testing
- 9 Code Reviews
- 10 Robust Implementation of Several Simple Algorithms
- 11 Object-Oriented Programming
- 12 Parallel Programming
- A Tools for Development and Maintenance
- B Caveats
- C Trademarks
- Bibliography
- Index
6 - Interfacing to C: SQLite As an Example
Published online by Cambridge University Press: 05 July 2012
- Frontmatter
- Contents
- Foreword
- Preface
- 1 Introduction to Modern Fortran
- 2 Array-Valued Functions
- 3 Mathematical Abstractions
- 4 Memory Management
- 5 An Interface Problem
- 6 Interfacing to C: SQLite As an Example
- 7 Graphics, GUIs, and the Internet
- 8 Unit Testing
- 9 Code Reviews
- 10 Robust Implementation of Several Simple Algorithms
- 11 Object-Oriented Programming
- 12 Parallel Programming
- A Tools for Development and Maintenance
- B Caveats
- C Trademarks
- Bibliography
- Index
Summary
Quite often the public interface of a library that you are interested in is written in a different programming language than the one you use. You will need an interface library that bridges the gap between both languages. This is the case with SQLite, a lightweight database management system [44]. It is written in C and there is a host of libraries to communicate with SQLite in all manner of languages.
For Fortran, there is the fsqlite library that I developed. It was inspired by the work of Al Danial [27], but focused on FORTRAN 77, that was mainly an example of how you could interface to the SQLite library. I wanted a generic solution instead.
The design decisions and the implementation of fsqlite illustrate a more general question: how to combine Fortran and other programming languages? Each time you need to consider:
■ Low-level aspects of the combination:
- How do the basic types of the two languages relate to each other?
- What are the naming and calling conventions?
■ High-level aspects relating to the actual library: What is a good “model” for the interface? Should you simply write wrapping routines that merely translate the routine interfaces or should you build a higher-level interface, molding the original interface into something that is a better fit for the library's use?
This chapter will cover both types of issues in the context of interfacing with C (an intermediate layer in C is often a convenient way to communicate with any other language) and of the interface to SQLite.
- Type
- Chapter
- Information
- Modern Fortran in Practice , pp. 76 - 91Publisher: Cambridge University PressPrint publication year: 2012