X hits on this document

883 views

0 shares

0 downloads

0 comments

335 / 396

C# LANGUAGE SPECIFICATION

Mappings between pointers and integers are implementation-defined. However, on 32- and 64-bit CPU architectures with a linear address space, conversions of pointers to or from integral types typically behave exactly like conversions of uint or ulong values, respectively, to or from those integral types.

18.5 Pointers in expressions

In an unsafe context, an expression may yield a result of a pointer type, but outside an unsafe context it is a compile-time error for an expression to be of a pointer type. In precise terms, outside an unsafe context a compile-time error occurs if any simple-name (§‎7.5.2), member-access (§‎7.5.4), invocation-expression (§‎7.5.5), or element-access (§‎7.5.6) is of a pointer type.

In an unsafe context, the primary-no-array-creation-expression (§‎7.5) and unary-expression (§‎7.6) productions permit the following additional constructs:

primary-no-array-creation-expression: ... pointer-member-access pointer-element-access sizeof-expression

unary-expression: ... pointer-indirection-expression addressof-expression

These constructs are described in the following sections. The precedence and associativity of the unsafe operators is implied by the grammar.

18.5.1 Pointer indirection

A pointer-indirection-expression consists of an asterisk (*) followed by a unary-expression.

pointer-indirection-expression: *   unary-expression

The unary * operator denotes pointer indirection and is used to obtain the variable to which a pointer points. The result of evaluating *P, where P is an expression of a pointer type T*, is a variable of type T. It is a compile-time error to apply the unary * operator to an expression of type void* or to an expression that isn’t of a pointer type.

The effect of applying the unary * operator to a null pointer is implementation-defined. In particular, there is no guarantee that this operation throws a System.NullReferenceException.

If an invalid value has been assigned to the pointer, the behavior of the unary * operator is undefined. Among the invalid values for dereferencing a pointer by the unary * operator are an address inappropriately aligned for the type pointed to (see example in §‎18.4), and the address of a variable after the end of its lifetime.

For purposes of definite assignment analysis, a variable produced by evaluating an expression of the form *P is considered initially assigned (§‎5.3.1).

18.5.2 Pointer member access

A pointer-member-access consists of a primary-expression, followed by a “->” token, followed by an identifier.

pointer-member-access: primary-expression   ->   identifier

In a pointer member access of the form P->I, P must be an expression of a pointer type other than void*, and I must denote an accessible member of the type to which P points.

322Copyright Microsoft Corporation 1999-2003. All Rights Reserved.

Document info
Document views883
Page views883
Page last viewedTue Dec 06 00:05:39 UTC 2016
Pages396
Paragraphs9401
Words133190

Comments