Oddly, two computing platforms that both use binary representation of integers might not represent the same number identically. Intel machines, for example, store bytes using the Little Endian architecture, whereas Motorola processors, IBM mainframe computers, SPARC processors, and ARM processors employ the Big Endian scheme. (However, the last two systems can be configured to use either scheme.)

The terms Big Endian and Little Endian can be thought of as meaning “Big End In” and “Little End In”—a reference to the order of bytes in a word (typically a 2-byte unit) of memory. On an Intel computer (Little Endian), the low-order byte is stored first. This means a hex value such as 0xABCD would be stored in memory as 0xCD 0xAB. A Motorola (Big Endian) machine would store the same value in reverse, so 0xABCD would be stored in memory as 0xAB 0xCD.

Jonathan Swift’s book Gulliver’s Travels is the ultimate source for these terms. Swift satirized the irrationality of many political disputes by inventing two contentious political factions in Lilliput: the Big Endians, who maintained that the proper end to break an egg is the large end, and the Little Endians, who championed breaking the small end of the egg.

You, as a software engineer, should understand the word order of the platform you are targeting. Among other things, it affects the interpretation of data transmitted over a network and how data is stored in binary files. In the preceding example, the 2-byte memory pattern 0xABCD would represent the decimal value 52,651 on a Little Endian machine and the decimal value 43,981 on a Big Endian machine.

B. C++ Reserved Words

C++ reserves some words for its own use and for use in C++ libraries. You shouldn’t use a reserved word as an identifier in a declaration. Reserved words come in three categories: keywords, alternative tokens, and C++ library reserved names.

C++ Keywords

Keywords are identifiers that form the vocabulary of a programming language. They may not be used for other purposes, such as serving as variable names. Table B.1 shows C++’s keywords. Keywords shown in boldface are also keywords in ANSI C99. Keywords in italics are C++11 additions.

Table B.1. C++ Keywords

Alternative Tokens

In addition to keywords, C++ has some alphabetic alternative representations of operators, termed alternative tokens. These, too, are reserved. Table B.2 lists the alphabetic alternative tokens and the operators they represent.

Table B.2. C++ Reserved Alternative Tokens and Their Meanings

C++ Library Reserved Names

The compiler won’t let you use keywords and alternative tokens as names. There’s another class of forbidden names for which the protection is not as absolute—reserved names, which are names reserved for use by the C++ library. If you use one of these as an identifier, the effect is undefined. That is, it might generate a compiler error, it might generate a warning, it might cause a program to run incorrectly, or it might cause no problems at all.

The C++ language reserves macro names used in a library header file. If a program includes a particular header file, then you shouldn’t use the names of macros defined in that header (or in headers included by that header file, and so on) for other purposes. For example, if you include the header file directly or indirectly, you shouldn’t use CHAR_BIT as an identifier because that name is already used as a macro in that header file.

The C++ language reserves names beginning with two underscores or a single underscore followed by an uppercase letter for any use, and it reserves names beginning with a single underscore for use as a global variable. So don’t create names such as __gink or __Lynx in any case and names such as _lynx in the global namespace.

The C++ language reserves names declared with external linkage in library header files. For functions, this includes the function signature (name and parameter list). For example, suppose you have this code:

#include

using namespace std;

In this case, the function signature tan(double) is reserved. That means your program should not declare a function that has this prototype:

int tan(double);  // don't do it

This doesn’t match the library tan() prototype, which returns type double, but it does match the signature portion. However, it would be okay to have the following prototype:

char * tan(char *);  // ok

That’s because even though it matches the tan() identifier, it doesn’t match the signature.

Identifiers With Special Meaning

Перейти на страницу:

Все книги серии Developer's Library

Похожие книги