On Monday, 12 February 2018 at 05:37:23 UTC, ketmar wrote:
Norm wrote:


I'm new to D so can someone explain to me what is happening here?

void func(const char* s, char** e) {
     import core.stdc.stdlib;
     auto result = strtod(s, e);

Error: function core.stdc.stdlib.strtod (scope inout(char)* nptr, scope inout(char)** endptr) is not callable using argument types (const(char*), char**)

there is a difference between `const char* s`, and `const(char)* s`. the former means that both `s` and `*s` cannot change, the latter means that `s` can be changed, but `*s` cannot. i.e. the first form means that you cannot do pointer arithmetic with `s`, while with second form you can (only *contents* are const, not the pointer itself).

that is, `strtod` wants const *contents*, but not pointer. `const(char)* s`.

I tried variations of const (char)* s, ... etc. and then stupidly realised the problem was with the second parameter 'e'. inout does behave the way I expected, I was just looking at the wrong parameter.

My silly mistake but thanks for your reply.


Reply via email to