[Mono-dev] String comparison failing between C# and C
robertj at gmx.net
Thu Nov 15 16:24:40 EST 2007
Dan Osawa wrote:
> 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
The error is most likely in your C code you didn't post.
You're probably returning a const ptr to a string:
This is wrong. The interop rules demand that that string was
allocated from the heap:
return strdup ("hello");
More information about the Mono-devel-list