Skip to main content Accessibility help
×
Hostname: page-component-76fb5796d-22dnz Total loading time: 0 Render date: 2024-04-25T19:08:00.643Z Has data issue: false hasContentIssue false

6 - Scalar Types

Published online by Cambridge University Press:  05 July 2014

Get access

Summary

This chapter lays the foundations for the small-scale aspects of Ada. We start by considering the declaration of objects and the assignment of values to them and briefly discuss the ideas of scope and visibility. We then introduce the important concepts of type, subtype and constraints. As examples of types, the remainder of the chapter discusses the numeric types Integer and Float, enumeration types in general, the type Boolean in particular, and the operations on them.

Object declarations and assignments

Values can be stored in objects which are declared to be of a specific type. Objects are either variables, in which case their value may change (or vary) as the program executes, or they may be constants, in which case they keep their same initial value throughout their life.

A variable is introduced into the program by a declaration which consists of the name (that is, the identifier) of the variable followed by a colon and then the name of the type. This can then optionally be followed by the := symbol and an expression giving the initial value. The declaration terminates with a semicolon. Thus we might write

J: Integer;

P: Integer := 38;

The first declaration introduces the variable J of type Integer but gives it no particular initial value. The second introduces the variable P and gives it the specific initial value of 38.

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.

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

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

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