Skip to main content Accessibility help
×
Hostname: page-component-78c5997874-xbtfd Total loading time: 0 Render date: 2024-11-05T23:22:24.096Z Has data issue: false hasContentIssue false

10 - Generic Programming

Published online by Cambridge University Press:  05 December 2011

Walter Spector
Affiliation:
Silicon Graphics, Inc., Fremont, California
Get access

Summary

A common requirement when writing code is the ability to use the identical, or nearly identical, code for different data types. In the case of the public domain LAPACK linear algebra library (see Reference [5]), for instance, procedures support much the same set of operations for each of real, double precision, and complex data types. For example, the real version of a matrix operation routine might be identical to the complex version, except for a few details, primarily:

  • The data type of the dummy arguments.

  • The data type of function return values.

  • The data type of localized temporary variables.

  • Numeric constants (e.g., 1.0 vs (1.0,0.0)).

In addition to the data type, the kind and rank of arguments may also differ. A routine that processes real data may be identical to its double precision counterpart, thereby making the kinds different. And often routines accepting scalar arguments may need to be expanded to accept array arguments.

A number of techniques are used to make the job of generic programming easier and less error prone than simply replicating and hand-editing code. These techniques can be divided into three general methodologies: reducing the need to replicate code, reducing the number of code changes required to replicate code, and finally, automating the replication of code. The specific techniques we discuss are:

  • Use parameterized derived types to avoid replication based on kind and len.

  • Create and use generic names for procedures with interface blocks.

  • […]

Type
Chapter
Information
Modern Fortran
Style and Usage
, pp. 171 - 182
Publisher: Cambridge University Press
Print publication year: 2011

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 [email protected] 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.

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.

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.

Available formats
×