Chapter 5. Basic values and data

 

This chapter covers

  • Understanding the abstract state machine
  • Working with types and values
  • Initializing variables
  • Using named constants
  • Binary representations of types

We will now change our focus from “how things are to be done” (statements and expressions) to the things on which C programs operate: valuesC and dataC. A concrete program at an instance in time has to represent values. Humans have a similar strategy: nowadays we use a decimal presentation to write numbers on paper using the Hindu-Arabic numeral system. But we have other systems to write numbers: for example, Roman numerals (i, ii, iii, iv, and so on) or textual notation. To know that the word twelve denotes the value 12 is a nontrivial step and reminds us that European languages denote numbers not only in decimal but also in other systems. English and German mix with base 12, French with bases 16 and 20. For non-native French speakers like myself, it may be difficult to spontaneously associate quatre vingt quinze (four times twenty and fifteen) with the value 95.

Similarly, representations of values on a computer can vary “culturally” from architecture to architecture or are determined by the type the programmer gave to the value. Therefore, we should try to reason primarily about values and not about representations if we want to write portable code.

5.1. The abstract state machine

5.1.1. Values

5.1.2. Types

5.1.3. Binary representation and the abstract state machine

5.1.4. Optimization

5.2. Basic types

5.3. Specifying values

5.3.1. Complex constants

5.4. Implicit conversions

5.5. Initializers

5.6. Named constants

5.6.1. Read-only objects

5.6.2. Enumerations

5.6.3. Macros

5.6.4. Compound literals

5.7. Binary representions

5.7.1. Unsigned integers

5.7.2. Bit sets and bitwise operators

5.7.3. Shift operators

5.7.4. Boolean values

5.7.5. Signed integers

5.7.6. Fixed-width integer types

5.7.7. Floating-point data

Summary

sitemap