Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Alias to pointer (byte*) in C#

Is it possible to make an alias on unsafe pointer type, i.e. I wanna use following: using bytePtr = System.Byte*.

Will .net developers introduce this feature in future versions (alias to pointer and array types)?

like image 486
Ivan Kochurkin Avatar asked Nov 21 '12 09:11

Ivan Kochurkin


People also ask

Can alias be given to pointers in C?

Because any pointer could alias any other pointer in C, the compiler must assume that memory regions accessed through these pointers can overlap, which prevents many possible optimizations. C++ enables more optimizations, as pointer arguments will not be treated as possible aliases if they point to different types.

What is pointer aliasing in C?

Pointer aliasing is a hidden kind of data dependency that can occur in C, C++, or any other language that uses pointers for array addresses in arithmetic operations. Array data identified by pointers in C can overlap, because the C language puts very few restrictions on pointers.


1 Answers

No, it isn't.

And if it was, the syntax would have been:

using BytePtr = System.Byte*;

but again: no, you can't do that. A using alias can not be to a pointer.

Also, byte* is both shorter and clearer than BytePtr, IMO.

like image 136
Marc Gravell Avatar answered Sep 17 '22 17:09

Marc Gravell