Section 4.1 C/C++ Basic Data Types
The ARM architecture defines several data types for both the 32- and 64-bit implementations. Table 4.1.1 shows the names for both implementations for completeness. As of this writing (September 2017) Raspbian only runs the Raspberry Pi in 32-bit mode.
|Name||Size (bits)||Architecture (32/64 bit)|
C and C++ provide several data types. Their sizes for the 32-bit ARM architecture are shown in Table 4.1.2.
||Word||Single-precision IEEE floating-point|
||Doubleword||Double-precision IEEE floating-point|
||Word||Address of data or code|
In the 64-bit version (not the current Raspbian) the sizes are the same, except the
void* data type is a Doubleword (64 bits).
A given “real world” value can usually be represented in more than one data type. For example, most people would think of “123” as representing “one hundred twenty-three.” This value could be stored in a computer in
int format or
char format, with each
char holding one of the characters in this number. An
int in our C/C++ environment is stored in 32 bits, and the bit pattern would be
As a C-style text string it would also require four bytes of memory, but their bit patterns would be
(Recall that a C-style string is terminated with a
int format is easier to use in arithmetic and logical expressions, but the interface with the outside world through the screen and the keyboard uses the
char format. If a user entered “\(123\)” from the keyboard, the operating system would read the individual characters, each in
char format, and store them as a text string. The text string must be converted to
int format. After the numbers are manipulated, the result must be converted from the
int format to
char format for display on the screen.
On the other hand, if the program primarily manipulates the numbers as text, rather than in arithmetic computations, it may be more efficient to keep them stored as text strings.
C programmers use functions in the
stdio library and C++ programmers use functions in the
iostream library to do these conversions between the
char formats. For example, the C code sequence:
scanf("%d", &x); x += 100; printf("%d", x);
or the C++ code sequence:
cin >> x; x += 100; cout << x;
Reads characters, each as a separate
charfrom the keyboard and converts the
charsequence into the corresponding
Adds 100 to the
Converts the resulting
charsequence and displays it on the screen.
The C or C++ I/O library functions in the code segments above do the necessary conversions between
char sequences and the
int storage format. However, once the conversion is performed, they ultimately call the
read system call function to read bytes from the keyboard and the
write system call function to write bytes to the screen. As shown in Figure 4.1.3, an application program can call the
write functions directly to transfer bytes.
When using the
write system call functions for I/O, it is the programmer's responsibility to do the conversions between the
char type used for I/O and the storage formats used within the program. We will soon be writing our own functions in assembly language to convert between the character format used for screen display and keyboard input, and the internal storage format of integers in the binary number system. The purpose of writing our own functions is to gain a thorough understanding of how data is represented internally in the computer.