Am I doing it wrong or is this a bug ?

Mafi mafi at example.org
Thu Aug 12 07:09:27 PDT 2010


Am 12.08.2010 15:59, schrieb Ezneh:
> Richard Webb Wrote:
>
>> Is returning a D string to a non-D language going to cause problems?
>
> Hmm it seems that returning an int works but returning string / char types doesn't work ...
>
>
> Anyone knows why ?
Hi,
returning an int works because D's int and most other language's (eg 
C's) int are identical. D's string is an alias for 'immutable(char)[]'. 
The brackets [] idicate an D array. D arrays are not the same as C 
arrays. In C strings are char* pointing to a null terminated sequence of 
chars. In D they are more complicated.
Just let your function return char* replace 'return xy;' with 'return 
toStringz(xy);'. Then put 'import std.string' at the begining of your 
file. Then you do this your function will return c-like strings for 
interfacing with C and C++.


More information about the Digitalmars-d mailing list