Thread overview | |||||||
---|---|---|---|---|---|---|---|
|
July 17, 2017 (char* str) is not callable using argument types (string) | ||||
---|---|---|---|---|
| ||||
I am Developing and Operation System in D and when writing writeln("Zaheer"); function, I got an ERROR. Error: function kernel.dwriteln (char* str) is not callable using argument types (string) I also tried Casting. I Developed OS in C and C++ but first time stuck in types. |
July 17, 2017 Re: (char* str) is not callable using argument types (string) | ||||
---|---|---|---|---|
| ||||
Posted in reply to Zaheer Ahmed | On Monday, 17 July 2017 at 13:56:24 UTC, Zaheer Ahmed wrote:
> I Developed OS in C and C++ but first time stuck in types.
A lot of C and C++ knowledge will carry over to D, but it isn't exactly the same. D's strings are of type `string` which is another word for `immutable(char)[]`.
immutable means the contents never change. A `[]` slice is a pointer+length pair in a single type.
For your simple case, making it `const char*` should work... but you might want to read up on D's const and array types before going to much further.
|
July 17, 2017 Re: (char* str) is not callable using argument types (string) | ||||
---|---|---|---|---|
| ||||
Posted in reply to Adam D. Ruppe | On Monday, 17 July 2017 at 14:10:39 UTC, Adam D. Ruppe wrote:
> On Monday, 17 July 2017 at 13:56:24 UTC, Zaheer Ahmed wrote:
>> I Developed OS in C and C++ but first time stuck in types.
>
> A lot of C and C++ knowledge will carry over to D, but it isn't exactly the same. D's strings are of type `string` which is another word for `immutable(char)[]`.
>
> immutable means the contents never change. A `[]` slice is a pointer+length pair in a single type.
>
>
> For your simple case, making it `const char*` should work... but you might want to read up on D's const and array types before going to much further.
Thank you It worked.
|
July 18, 2017 Re: (char* str) is not callable using argument types (string) | ||||
---|---|---|---|---|
| ||||
Posted in reply to Adam D. Ruppe | On 07/17/2017 05:10 PM, Adam D. Ruppe wrote:
> On Monday, 17 July 2017 at 13:56:24 UTC, Zaheer Ahmed wrote:
>> I Developed OS in C and C++ but first time stuck in types.
>
> A lot of C and C++ knowledge will carry over to D, but it isn't exactly the same. D's strings are of type `string` which is another word for `immutable(char)[]`.
>
> immutable means the contents never change. A `[]` slice is a pointer+length pair in a single type.
>
>
> For your simple case, making it `const char*` should work...
No, it shouldn't.
Worst, it should work *most* of the time.
If you cast a D string to const char* may or may not null terminate the string.
Shachar
|
July 18, 2017 Re: (char* str) is not callable using argument types (string) | ||||
---|---|---|---|---|
| ||||
Posted in reply to Shachar Shemesh | On Tuesday, 18 July 2017 at 03:58:49 UTC, Shachar Shemesh wrote:
> If you cast a D string to const char* may or may not null terminate the string.
I do not recommend explicitly casting. This specific case is a string literal, which is guaranteed to be null terminated and will implicitly cast.
In the cases where it is not null terminated, the compiler will reject it as a type error.
|
Copyright © 1999-2021 by the D Language Foundation