BT

InfoQ Homepage News C# Futures: Pointer Math

C# Futures: Pointer Math

This item in japanese

Bookmarks

Interoperability with native platforms often require very specific coding patterns that involve the manipulation of pointers. While this can be done via a shim written in C, the proposal titled Operators should be exposed for System.IntPtr and System.UIntPtr seeks to offer that ability directly in C#.

The ability to directly manipulate pointers has always been part of the Common Language Runtime (CLR). As the name suggests, the CLR was designed to support a wide variety of languages including “low level” languages such as C++. As such, it includes things not deemed necessary by the original .NET languages: VB, C#, J#, and JScript.NET (the latter two are no longer offered).

Fourteen operators are covered by this proposal: Add, Divide, Multiply, Remainder, Subtract, Negate, Equals, Compare, And, Not, Or, XOr, ShiftLeft, ShiftRight. The proposal claims, “The unverifiable operators defined by the CLI spec are not listed and are not currently part of this proposal (although it may be worth considering these as well).”

This statement is not elaborated on, though this passage from the CLI standard explains the meaning of “verifiable”,

The difference between type-safe code and verifiable code is one of provability: code which passes the VES verification algorithm is, by-definition, verifiable; but that simple algorithm rejects certain code, even though a deeper analysis would reveal it as genuinely type-safe. Note that even if a program follows the syntax described in Partition VI, the code might still not be valid, because valid code shall adhere to restrictions presented in this Partition and in Partition III.

The verification process is very stringent. There are many programs that will pass validation, but will fail verification. The VES cannot guarantee that these programs do not access memory or resources to which they are not granted access. Nonetheless, they might have been correctly constructed so that they do not access these resources. It is thus a matter of trust, rather than mathematical proof, whether it is safe to run these programs. Ordinarily, a conforming implementation of the CLI can allow unverifiable code (valid code that does not pass verification) to be executed, although this can be subject to administrative trust controls that are not part of this standard. A conforming implementation of the CLI shall allow the execution of verifiable code, although this can be subject to additional implementation-specified trust controls.

Presumably these operations would only be allowed in an unsafe context. However, the proposal doesn’t explicitly state this.

As with other features in our C# Futures series, this proposal is under consideration and not yet part of the C# road map.

Rate this Article

Adoption
Style

Hello stranger!

You need to Register an InfoQ account or or login to post comments. But there's so much more behind being registered.

Get the most out of the InfoQ experience.

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Community comments

  • Missing C++ as original .NET language

    by Paulo Pinto /

    Your message is awaiting moderation. Thank you for participating in the discussion.

    C++ has always been part of .NET, initially via Managed C++, later replaced by C++/CLI.

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

BT

Is your profile up-to-date? Please take a moment to review and update.

Note: If updating/changing your email, a validation request will be sent

Company name:
Company role:
Company size:
Country/Zone:
State/Province/Region:
You will be sent an email to validate the new email address. This pop-up will close itself in a few moments.