Team LiB
Previous Section Next Section

Defined Terms

术语

C-style strings(C 风格字符串)

C programs treat pointers to null-terminated character arrays as strings. In C++, string literals are C-style strings. The C library defines a set of functions that operate on such strings, which C++ makes available in the cstring header. C++ programs should use C++ library strings in preference to C-style strings, which are inherently error-prone. A sizeable majority of security holes in networked programs are due to bugs related to using C-style strings and arrays.

C 程序把指向以空字符结束的字符数组的指针视为字符串。在 C++ 中,字符串字面值就是 C 风格字符串。C 标准库定义了一系列处理这种字符串的库函数,C++ 中将这些标准库函数放在 cstring 头文件中。由于 C 风格字符串本质上容易出错,C++ 程序应该优先使用 C++ 标准库类 string 而少用 C 风格字符串。网络程序中大量的安全漏洞都源于与使用 C 风格字符串和数组相关的缺陷。

compiler extension(编译器扩展)

Feature that is added to the language by a particular compiler. Programs that rely on compiler extensions cannot be moved easily to other compilers.

特定编译器为语言添加的特性。依赖于编译器扩展的程序很难移植到其他的编译器。

compound type(复合类型)

Type that is defined in terms of another type. Arrays, pointers, and references are compound types.

使用其他类型定义的类型。数组、指针和引用都是复合类型。

const void*

A pointer type that can point to any const type. See void*.

可以指向任意 const 类型的指针类型,参见 void *

delete expression(delete 表达式)

A delete expression frees memory that was allocated by new:

delete 表达式用于释放由 new 动态分配的内存:

     delete [] p;

where p must be a pointer to the first element in a dynamically allocated array. The bracket pair is essential: It indicates to the compiler that the pointer points at an array, not at a single object. In C++ programs, delete replaces the use of the C library free function.

在此表达式中,p 必须是指向动态创建的数组中第一个元素的指针,其中方括号必不可少:它告诉编译器该指针指向数组,而非单个对象。C++ 程序使用 delete 取代 C 语言的标准库函数 free

dimension(维数)

The size of an array.

数组大小。

dynamically allocated(动态分配的)

An object that is allocated on the program's free store. Objects allocated on the free store exist until they are explicitly deleted.

在程序自由存储区中建立的对象。该对象一经创建就一直存在,直到显式释放为止。

free store(自由存储区)

Memory pool available to a program to hold dynamically allocated objects.

程序用来存储动态创建对象的内存区域。

heap(堆)

Synonym for free store.

自由存储区的同义词。

new expression(new表达式)

Allocates dynamic memory. We allocate an array of n elements as follows:

用于分配动态内存的表达式。下面的语句分配了一个有 n 个元素的数组:

     new type[n];

The array holds elements of the indicated type. new returns a pointer to the first element in the array. C++ programs use new in place of the C library malloc function.

该数组存放 type 类型的元素。new 返回指向该数组第一个元素的指针。C++ 程序使用 new 取代 C 语言的标准库函数 malloc

pointer(指针)

An object that holds the address of an object.

存放对象地址的对象。

pointer arithmetic(指针算术操作)

The arithmetic operations that can be applied to pointers. An integral type can be added to or subtracted from a pointer, resulting in a pointer positioned that many elements ahead or behind the original pointer. Two pointers can be subtracted, yielding the difference between the pointers. Pointer arithmetic is valid only on pointers that denote elements in the same array or an element one past the end of that array.

可用于指针的算术操作。允许在指针上做加上或减去整型值的操作,以获得当前指针之前或之后若干个元素处的地址。两个指针可做减法操作,得到它们之间的差值。只有当指针指向同一个数组或其超出末端的位置时,指针的算术操作才有意义。

precedence(优先级)

Defines the order in which operands are grouped with operators in a compound expression.

在复杂的表达式中,优先级确定了操作数分组的次序。

ptrdiff_t

Machine-dependent signed integral type defined in cstddef header that is large enough to hold the difference between two pointers into the largest possible array.

cstddef 头文件中定义的与机器相关的有符号整型,该类型具有足够的大小存储两个指针的差值,这两个指针指向同一个可能的最大数组。

size_t

Machine-dependent unsigned integral type defined in cstddef header that is large enough to hold the size of the largest possible array.

cstddef 头文件中定义的与机器相关的无符号整型,它具有足够的大小存储一个可能的最大数组。

* operator(* 操作符)

Dereferencing a pointer yields the object to which the pointer points. The dereference operator returns an lvalue; we may assign to the value returned from the dereference operator, which has the effect of assigning a new value to the underlying element.

对指针进行解引用操作获得该指针所指向的对象。解引用操作符返回左值,因此可为其结果赋值,等效于为该指针所指向的特定对象赋新值。

++ operator(++ 操作符)

When used with a pointer, the increment operator "adds one" by moving the pointer to refer to the next element in an array.

用于指针时,自增操作符给指针“加 1”,移动指针使其指向数组的下一个元素。

[] operator([] 操作符)

The subscript operator takes two operands: a pointer to an element of an array and an index. Its result is the element that is offset from the pointer by the index. Indices count from zerothe first element in an array is element 0, and the last is element size of the array minus 1. The subscript operator returns an lvalue; we may use a subscript as the left-hand operand of an assignment, which has the effect of assigning a new value to the indexed element.

下标操作符接受两个操作数:一个是指向数组元素的指针,一个是下标 n。该操作返回偏离指针当前指向 n 个位置的元素值。数组下标从 0 开始计数——数组第一个元素的下标为 0,最后一个元素的下标是数组长度减 1。下标操作返回左值,可用做赋值操作的左操作数,等效于为该下标引用的元素赋新值。

& operator(& 操作符)

The address-of operator. Takes a single argument that must be an lvalue. Yields the address in memory of that object.

取地址操作符需要一个操作数,其唯一的操作数必须是左值对象,该操作返回操作数对象在内存中的存储地址。

void*

A pointer type that can point to any nonconst type. Only limited operations are permitted on void* pointers. They can be passed or returned from functions and they can be compared with other pointers. They may not be dereferenced.

可以指向任何非 const 对象的指针类型。void* 指针只提供有限的几种操作:可用作函数形参类型或返回类型,也可与其他指针做比较操作,但是不能进行解引用操作。

Team LiB
Previous Section Next Section