ILSpy
ILSpy copied to clipboard
Redundant cast
Input code
void Method1() {
int i4 = 0;
void* i = null;
void* result = (void*)((byte*)i4 - (byte*)i);
}
Erroneous output
void Method1()
{
int i2 = 0;
void* i = null;
void* result = (void*)(IntPtr)(void*)((long)(IntPtr)(void*)((long)i2 - (long)i) / 1L);
}
Details
ilspy v6.2.0.6118-preview2
Which cast to you think is redundant? I guess there's an argument that the code should be:
void* result = (void*)((long)(IntPtr)(void*)((long)i2 - (long)i) / 1L);
as the last two casts are indeed completely redundant.
The intermediate cast through IntPtr is relevant to trim the result down to native int size. There's no decent other way of doing this when the C# 9 nint feature isn't available.
could it be decompiled into 'i1* sub i1*' 'i2* sub i2*' by pattern matching, like (byte*)a - (byte*)b