Skip to main content Accessibility help
×
Hostname: page-component-7bb8b95d7b-495rp Total loading time: 0 Render date: 2024-09-27T03:43:05.999Z Has data issue: false hasContentIssue false

11 - Access Types

Published online by Cambridge University Press:  05 July 2014

Get access

Summary

This last chapter concerning the small-scale aspects of Ada is about access types. These are often known as pointer types, reference types or simply addresses in other languages and provide indirect access to other entities.

Playing with pointers is like playing with fire. Fire is perhaps the most important tool known to man. Carefully used, fire brings enormous benefits; but when fire gets out of control, disaster strikes. Pointers have similar characteristics but are well tamed in the form of access types in Ada.

This taming is done through the notion of accessibility which is discussed in some detail in Sections 11.5 and 11.6. Parts of these sections might be found hard to digest and could well be skipped at a first reading.

There are two forms of access types, those which access objects and those which access subprograms. Their type may be named or anonymous. Of particular importance are parameters of an anonymous access type. The related access discriminants are discussed in Chapter 18.

Flexibility versus integrity

The manipulation of objects by referring to them indirectly through values of other objects is a common feature of most programming languages. It is also a contentious topic since, although the technique provides considerable flexibility, it is also the cause of many programming errors and moreover, used incautiously, can make programs very hard to understand and maintain. It is worth a historical digression in order to place Ada in perspective.

Algol 68 was an early language to use indirection and used the term references. Indeed the definition of Algol 68 revolved around references to such an extent that it created the impression that the language was academically elaborate. There were also technical difficulties of dangling references, that is variables pointing to objects that no longer exist.

BCPL, from which C was derived, used references or pointers as the foundation of its storage model. Arrays were just seen as objects that could be referred to dynamically by adding an index to a base address. Thus the natural implementation model was made visible in the language itself. This almost negative abstraction was perhaps a great mistake and a step backwards in the evolution of abstraction as the driving force in language design.

C has inherited the BCPL model and it is considered quite normal practice in C to add integers to pointers (addresses) thereby creating implementation dependencies and complete freedom to do silly things.

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

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.

  • Access Types
  • John Barnes
  • Book: Programming in Ada 2012
  • Online publication: 05 July 2014
  • Chapter DOI: https://doi.org/10.1017/CBO9781139696616.016
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.

  • Access Types
  • John Barnes
  • Book: Programming in Ada 2012
  • Online publication: 05 July 2014
  • Chapter DOI: https://doi.org/10.1017/CBO9781139696616.016
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.

  • Access Types
  • John Barnes
  • Book: Programming in Ada 2012
  • Online publication: 05 July 2014
  • Chapter DOI: https://doi.org/10.1017/CBO9781139696616.016
Available formats
×