fromStringz problem with gdc
bachmeier via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Mon Apr 6 12:44:32 PDT 2015
On Monday, 6 April 2015 at 18:31:13 UTC, chardetm wrote:
> On Monday, 6 April 2015 at 17:55:42 UTC, Iain Buclaw wrote:
>> On Monday, 6 April 2015 at 17:47:27 UTC, chardetm wrote:
>>> Hello everyone,
>>>
>>> I have a problem with the fromStringz function
>>> (std.string.fromStringz) when I try to compile with the GDC
>>> compiler (it works fine with DMD).
>>>
>>> Here is a minimal code to see the error:
>>>
>>>
>>> import std.stdio, std.string, std.c.stdlib;
>>>
>>> int main () {
>>> char* s;
>>> s = cast(char*) malloc(2);
>>> s[0] = 'a';
>>> s[1] = '\0';
>>> writeln(fromStringz(s));
>>> return 0;
>>> }
>>>
>>>
>>> Compiling with DMD (works fine):
>>> $ dmd testfsz.d
>>>
>>> Compiling with GDC:
>>> $ gdc testfsz.d -o testfsz
>>> testfsz.d:8: error: undefined identifier fromStringz
>>>
>>> It does the same thing on a friend's computer. I'm using GCC
>>> 4.9.1 on Kubuntu 14.10.
>>> Any idea where this comes from? Thanks in advance for your
>>> help!
>>
>> fromStringz (in std.string) was introduced in D 2.066, gdc-4.9
>> was shipped when 2.065 was released.
>>
>> Iain.
>
> Thanks! I will make my own version and use conditional
> compilation to import it or not in that case...
Looks like the function itself is very short:
inout(char)[] fromStringz(inout(char)* cString) @system pure {
import core.stdc.string : strlen;
return cString ? cString[0 .. strlen(cString)] : null;
}
More information about the Digitalmars-d-learn
mailing list