Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
C-sharp language specification.2004.pdf
Скачиваний:
14
Добавлен:
23.08.2013
Размер:
2.55 Mб
Скачать

C# LANGUAGE SPECIFICATION

1The ++ and -- operators can be used to increment and decrement pointers (§25.5.5).

2The binary + and - operators can be used to perform pointer arithmetic (§25.5.6).

3The ==, !=, <, >, <=, and => operators can be used to compare pointers (§25.5.7).

4The stackalloc operator can be used to allocate memory from the call stack (§25.7).

5The fixed statement can be used to temporarily fix a variable so its address can be obtained (§25.6).

625.3 Fixed and moveable variables

7The address-of operator (§25.5.4) and the fixed statement (§25.6) divide variables into two categories:

8Fixed variables and moveable variables.

9Fixed variables reside in storage locations that are unaffected by operation of the garbage collector.

10(Examples of fixed variables include local variables, value parameters, and variables created by

11dereferencing pointers.) On the other hand, moveable variables reside in storage locations that are subject to

12relocation or disposal by the garbage collector. (Examples of moveable variables include fields in objects

13and elements of arrays.)

14The & operator (§25.5.4) permits the address of a fixed variable to be obtained without restrictions.

15However, because a moveable variable is subject to relocation or disposal by the garbage collector, the

16address of a moveable variable can only be obtained using a fixed statement (§25.6), and that address

17remains valid only for the duration of that fixed statement.

18In precise terms, a fixed variable is one of the following:

19A variable resulting from a simple-name (§14.5.2) that refers to a local variable or a value parameter, as

20long as the variable is not captured by an anonymous method (§14.5.14.3.1).

21A variable resulting from a member-access (§14.5.4) of the form V.I, where V is a fixed variable of a

22struct-type.

23A variable resulting from a pointer-indirection-expression (§25.5.1) of the form *P, a pointer-member-

24access (§25.5.2) of the form P->I, or a pointer-element-access (§25.5.3) of the form P[E].

25All other variables are classified as moveable variables.

26A static field is classified as a moveable variable. Also, a ref or out parameter is classified as a moveable

27variable, even if the argument given for the parameter is a fixed variable. Finally, a variable produced by

28dereferencing a pointer is always classified as a fixed variable.

2925.4 Pointer conversions

30In an unsafe context, the set of available implicit conversions (§13.1) is extended to include the following

31implicit pointer conversions:

32From any pointer-type to the type void*.

33From the null type to any pointer-type.

34Additionally, in an unsafe context, the set of available explicit conversions (§13.2) is extended to include the

35following explicit pointer conversions:

36From any pointer-type to any other pointer-type.

37From sbyte, byte, short, ushort, int, uint, long, or ulong to any pointer-type.

38From any pointer-type to sbyte, byte, short, ushort, int, uint, long, or ulong.

39Finally, in an unsafe context, the set of standard implicit conversions (§13.3.1) includes the following

40pointer conversion:

41From any pointer-type to the type void*.

384

Соседние файлы в предмете Электротехника