GC seems to crash my C-code function

Steven Schveighoffer schveiguy at gmail.com
Sun Sep 19 02:09:09 UTC 2021


On 9/18/21 5:20 PM, frame wrote:
> On Saturday, 18 September 2021 at 21:16:13 UTC, frame wrote:
>> On Saturday, 18 September 2021 at 18:48:07 UTC, Steven Schveighoffer 
>> wrote:
>>> Are you defining the prototype for strchr yourself instead of 
>>> importing it from core.stdc.string?
>>
>> Not really :D but without cast it complains:
>> ```
>> Error: cannot implicitly convert expression strchr(e, cast(int)c) of 
>> type const(char)* to char*
>> ```
> 
> But I guess it's because it tries to assign to a `char*` therefore 
> inout() doesn't work.
> 
> 

Well, the variable you are assigning it to should be a `const char *` if 
the source variable is a `const char *`.

Possibly, the C code didn't mark it as `const char *`, because I'm 
pretty sure C has `strchr` being:

`char * strchr(const char *, int)`

Because, you know, const doesn't matter in C ;)

If that doesn't work, then you *may* need to start allocating. But I'd 
try that first.

-Steve


More information about the Digitalmars-d-learn mailing list