The PInkove part was taken from some SO answer (sorry, I've lost the link to original).
Below is the complete program. The output is false
.
using System;
using System.Runtime.InteropServices;
namespace Memcpy
{
class Program
{
[DllImport("msvcrt.dll", CallingConvention = CallingConvention.Cdecl)]
private static extern int memcmp(Array b1, Array b2, long count);
public static bool CompareArrays(Array b1, Array b2)
{
// Validate buffers are the same length.
// This also ensures that the count does not exceed the length of either buffer.
return b1.Length == b2.Length && memcmp(b1, b2, b1.Length) == 0;
}
static void Main(string[] args)
{
var array1 = new int[,]
{
{0, 0, 0, 0, 0},
{0, 0, 0, 0, 0},
{0, 0, 0, 0, 0},
{0, 0, 0, 0, 0},
};
var array2 = new int[,]
{
{0, 0, 0, 0, 0},
{0, 0, 0, 0, 0},
{0, 0, 0, 0, 0},
{0, 0, 0, 0, 0},
};
Console.WriteLine(CompareArrays(array1, array2));
}
}
}
If I change arrays' size to 4x4 the output turns true
Why does memcmp behave this way?