digitalmars.D.learn - Error: cannot implicitly convert expression ("abcde") of type invariant char[5u] to char[]
- Tom McMurray <tomm pplus.com.au> Sep 05 2007
- BCS <ao pathlink.com> Sep 05 2007
- Daniel Keep <daniel.keep.lists gmail.com> Sep 05 2007
- torhu <no spam.invalid> Sep 05 2007
I just downloaded version 2.003 or DMD and tried to compile the following :-
class stringtest
{
void st1()
{
char[] s1 = "abcde";
}
}
This fails with the error :-
Error: cannot implicitly convert expression ("abcde") of type invariant
char[5u] to char[]
Is this a bug or am I doing something stupid. This code compiled successfully
on previous versions of the compiler. Any help would be appreciated
Sep 05 2007
Reply to Tom,I just downloaded version 2.003 or DMD and tried to compile the following :- class stringtest { void st1() { char[] s1 = "abcde"; } } This fails with the error :- Error: cannot implicitly convert expression ("abcde") of type invariant char[5u] to char[] Is this a bug or am I doing something stupid. This code compiled successfully on previous versions of the compiler. Any help would be appreciated
char[] s1 = "abcde"[]; this should work. (No comment on the issue)
Sep 05 2007
Tom McMurray wrote:I just downloaded version 2.003 or DMD and tried to compile the following :- class stringtest { void st1() { char[] s1 = "abcde"; } } This fails with the error :- Error: cannot implicitly convert expression ("abcde") of type invariant char[5u] to char[] Is this a bug or am I doing something stupid. This code compiled successfully on previous versions of the compiler. Any help would be appreciated
D 2.0 is not just the version after D 1.0; it has several breaking changes. This is not a bug: it is a side effect of the new const system in D 2.0. If you downloaded it thinking it was simply a newer compiler, you might be well advised to go back to the latest 1.x compiler. The 1.x series is now stable, and the 2.x series compilers could suddenly change at any moment. If you downloaded it because you want to play with D 2.0, then I suggest you re-read the language documentation. There are various bits and pieces that have changed, and it'll save you a lot of grief if you get a handle on it. -- Daniel P.S. To store a string literal into a char[] in D 2.0, you'll need to use "abcde".dup in order to make a mutable copy of the string.
Sep 05 2007
Tom McMurray wrote:I just downloaded version 2.003 or DMD and tried to compile the following :- class stringtest { void st1() { char[] s1 = "abcde"; } } This fails with the error :- Error: cannot implicitly convert expression ("abcde") of type invariant char[5u] to char[] Is this a bug or am I doing something stupid. This code compiled successfully on previous versions of the compiler. Any help would be appreciated
Try 'string' instead of 'char[]'. String is an alias for 'const(char)[]', which an 'invariant char[5u]' can be implicitly converted to. And I wouldn't write too much code for D 2.0 just yet, things might change. There was even talk of changing the const stuff.
Sep 05 2007









BCS <ao pathlink.com> 