Is it guaranted to work a conversion of a value type (such as int) to a byte pointer under any implementation of C#?
Like...
Code:byte *bp = (byte *)integer;
Printable View
Is it guaranted to work a conversion of a value type (such as int) to a byte pointer under any implementation of C#?
Like...
Code:byte *bp = (byte *)integer;
That code would never work because you are casting an int to a byte pointer (well, it may appear to 'work' depending on the value of 'integer' and what lies at that address in memory. It would most likely crash with a Null Reference exception when you tried to take the value at b). You code will set the pointer value itself to whatever the value of 'integer' is. For example, if 'integer' was '10'. your pointer would point to address '10', it would not point to a value of '10. It would have to be like this:
However, this is obviously a bad idea because you have a potential for a loss of data.Code:int i = 10;
byte* b = (byte*) &i;
C# is standardized, so yes, it would. I don't know of any other C# compilers though...