HomeiOS Developmentc# - Why is a 1 byte bool returns from reverse p/invoke...

c# – Why is a 1 byte bool returns from reverse p/invoke incorrectly evaluated on iOS ARM64?


Utilizing .NET 9, concentrating on iOS, I’ve one thing like this:


[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
[return: MarshalAs(UnmanagedType.U1)]
public delegate bool MyCallback();

// ...

personal static MyCallback _MyCallback = __MyCallback;

// ...

[ObjCRuntime.MonoPInvokeCallback(typeof(MyCallback))]
personal static bool __MyCallback()
{
    return false;
}

On the native facet:

typedef signed char BOOL;
typedef BOOL (*fnMyCallback)();

//

printf("sizeof(BOOL)=%zun", sizeof(BOOL));

if (!context->myCallback()
{
    printf("direct verify is FALSEn");
}
else
{
    printf(TAG, "direct verify is TRUEn");
}

Output is

sizeof(BOOL)=1
direct verify is TRUE

So, we verify that the worth we’re coping with is 1 byte on each managed and unmanaged sides. Why is it incorrectly evaluated as true?

This solely happens on iOS ARM64 in launch builds.

The C compiler is no matter we have now within the Xcode 16.4 toolchain.

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments