Skip to main content Accessibility help
×
Hostname: page-component-77c89778f8-vpsfw Total loading time: 0 Render date: 2024-07-22T07:25:42.931Z Has data issue: false hasContentIssue false

Appendix C - FORTRAN and C++

Published online by Cambridge University Press:  04 August 2010

Andi Klein
Affiliation:
Los Alamos National Laboratory
Alexander Godunov
Affiliation:
Old Dominion University, Virginia
Get access

Summary

Before we can discuss how to call FORTRAN functions from C++, we need first to look at some of the differences.

  1. The most important difference is that FORTRAN passes variables by reference, while C++, like C, passes by value. This in turn means that any FORTRAN routine expects to get a reference, so you have to make sure your program passes the variables appropriately.

  2. When you use arrays in your program, you have to take into account that the first array element in FORTRAN is a(1), while in C++ it would be a[0]. Multi-dimensional arrays are stored differently in memory. Array A(3,5) in FORTRAN would be A(1,1), A(2,1), A(3,1), A(1,2), while in C++ the corresponding arrangement would be A(0,0), A(0,1), A(0,2), A(0,3), A(0,4), A(1,0) and so on.

  3. C++ is a strongly typed language; if you do not define a variable your program will not compile. FORTRAN has by default an implicit type convention: any variable which starts with letters i through n is an integer, while any other variable is a real variable. Unless the programmer has used the “implicit none” statement any FORTRAN compiler will adhere to the standards.

  4. FORTRAN is case insensitive, while C++ clearly distinguishes between Dummy and dummy.

  5. […]

Type
Chapter
Information
Publisher: Cambridge University Press
Print publication year: 2006

Access options

Get access to the full version of this content by using one of the access options below. (Log in options will check for institutional or personal access. Content may require purchase if you do not have access.)

Save book to Kindle

To save this book to your Kindle, first ensure coreplatform@cambridge.org is added to your Approved Personal Document E-mail List under your Personal Document Settings on the Manage Your Content and Devices page of your Amazon account. Then enter the ‘name’ part of your Kindle email address below. Find out more about saving to your Kindle.

Note you can select to save to either the @free.kindle.com or @kindle.com variations. ‘@free.kindle.com’ emails are free but can only be saved to your device when it is connected to wi-fi. ‘@kindle.com’ emails can be delivered even when you are not connected to wi-fi, but note that service fees apply.

Find out more about the Kindle Personal Document Service.

  • FORTRAN and C++
  • Andi Klein, Los Alamos National Laboratory, Alexander Godunov, Old Dominion University, Virginia
  • Book: Introductory Computational Physics
  • Online publication: 04 August 2010
  • Chapter DOI: https://doi.org/10.1017/CBO9780511793219.015
Available formats
×

Save book to Dropbox

To save content items to your account, please confirm that you agree to abide by our usage policies. If this is the first time you use this feature, you will be asked to authorise Cambridge Core to connect with your account. Find out more about saving content to Dropbox.

  • FORTRAN and C++
  • Andi Klein, Los Alamos National Laboratory, Alexander Godunov, Old Dominion University, Virginia
  • Book: Introductory Computational Physics
  • Online publication: 04 August 2010
  • Chapter DOI: https://doi.org/10.1017/CBO9780511793219.015
Available formats
×

Save book to Google Drive

To save content items to your account, please confirm that you agree to abide by our usage policies. If this is the first time you use this feature, you will be asked to authorise Cambridge Core to connect with your account. Find out more about saving content to Google Drive.

  • FORTRAN and C++
  • Andi Klein, Los Alamos National Laboratory, Alexander Godunov, Old Dominion University, Virginia
  • Book: Introductory Computational Physics
  • Online publication: 04 August 2010
  • Chapter DOI: https://doi.org/10.1017/CBO9780511793219.015
Available formats
×