[Mono-dev] String comparison failing between C# and C
Dan Osawa
dkosawa at gmail.com
Thu Nov 15 16:18:16 EST 2007
Hello,
I'm currently testing Mono's interoperability between C# and C code, and
have run into an interesting scenario.
In my test case I have a C shared object that implements two functions:
setString and getString. The first function, setString, simply copies the
string into a local buffer. The second function, getString, returns a
pointer to the internal buffer holding the string.
What's interesting is that the first case (in the below C# code) fails when
it tries to compare "hello" against the return value of getString. Is this
a problem with trying to compare a unicode string with an ansi string? This
test case passes when running under Windows via CLR...fails in Linux via
Mono.
The second case, "hello" == s, passes.
namespace MonoEvaluation.Interop
{
public class Tester : ITester
{
[DllImport("InteropServerDllC")]
static extern void setString(string s);
[DllImport("InteropServerDllC")]
static extern string getString();
bool StringTest()
{
setString("hello");
string s = getString();
if ("hello" == getString())
{
Console.WriteLine("hello == getString passed!");
}
else
{
Console.WriteLine("hello == getString failed!");
return false;
}
if (("hello" == s)
{
Console.WriteLine("hello == s passed!");
}
else
{
Console.WriteLine("hello == s failed!");
return false;
}
return true;
}
}
}
I'm running this on an embedded PPC Arabella Linux system, using mono
version 1.2.5.1.
Thanks in Advance,
Dan
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.ximian.com/pipermail/mono-devel-list/attachments/20071115/6b6c21ae/attachment.html
More information about the Mono-devel-list
mailing list