Thread overview | |||||||||
---|---|---|---|---|---|---|---|---|---|
|
June 18, 2010 ERROR - "cannot implicitly convert expression (s) of type int[3u] to int*" | ||||
---|---|---|---|---|
| ||||
[NOTE - sent twice as I was unsure that first attempt, pre-subscription, was received.] Working through the basics of D and running into simple problems that I cannot solve, such as: Error: cannot implicitly convert expression (s) of type int[3u] to int* Error: cannot implicitly convert expression (a) of type int[] to int* Those are the result of code that I pulled directly from the D v1 docs from http://www.digitalmars.com/d/1.0/arrays.html Specifically, the code is this. int* p; int[3] s; int[] a; p = s; p = a; I initially encountered this problem with the mark/release example code from the D v2 docs - here: http://www.digitalmars.com/d/2.0/memory.html When I entered that code, it failed to compile. After debugging a few errors, such as std/outofmemory.d being replaced by core.memory, I was left w/ the same error as above but w/ void*/void[]. What is wrong w/ that ? How is it different from the docs that it does not work ? More importantly, what rule is being violated so that we won't encounter similar problems. I am using dmd v1.062 for v1 code, and dmd v2.047, downloaded and installed today onto a WinXP system. $ dmd -v Digital Mars D Compiler v1.062 Copyright (c) 1999-2010 by Digital Mars written by Walter Bright Documentation: http://www.digitalmars.com/d/1.0/index.html Usage: dmd files.d ... { -switch } $ dmd -v # different path from above Digital Mars D Compiler v2.047 Copyright (c) 1999-2010 by Digital Mars written by Walter Bright Documentation: http://www.digitalmars.com/d/2.0/index.html Usage: dmd files.d ... { -switch } Any help would be appreciated. D looks very promising for a real application that I need to write, as if it could provide the performance of C/C++ with the programmer-productivity of Perl/Python/etc. But if the time that we save writing the app in D will be lost to debugging simple problems like this then I won't have much of a choice. Thanks in advance. CHICKZ |
June 18, 2010 Re: ERROR - "cannot implicitly convert expression (s) of type int[3u] to int*" | ||||
---|---|---|---|---|
| ||||
Posted in reply to Chick Corea | On 06/18/2010 12:25 AM, Chick Corea wrote: > [NOTE - sent twice as I was unsure that first attempt, > pre-subscription, was received.] > > Working through the basics of D and running into simple problems that I > cannot solve, such as: > > Error: cannot implicitly convert expression (s) of type int[3u] to int* > Error: cannot implicitly convert expression (a) of type int[] to int* > > Those are the result of code that I pulled directly from the D v1 docs from > > http://www.digitalmars.com/d/1.0/arrays.html > > Specifically, the code is this. > > int* p; > int[3] s; > int[] a; > p = s; > p = a; > > I initially encountered this problem with the mark/release example code from > the D v2 docs - here: > > http://www.digitalmars.com/d/2.0/memory.html > > When I entered that code, it failed to compile. After debugging a few errors, > such as std/outofmemory.d being replaced by core.memory, I was left > w/ the same error as above but w/ void*/void[]. > > What is wrong w/ that ? How is it different from the docs that it does not > work ? More importantly, what rule is being violated so that we won't > encounter similar problems. > Rather simple. The docs are wrong (although I don't doubt that at some point in D's history the above was valid). Use p = s.ptr; instead of p = s; because arrays are not not not not not not not pointers. They're more of a struct{ size_t length; type* ptr; } > > Any help would be appreciated. D looks very promising for a real > application that I need to write, as if it could provide the performance > of C/C++ with the programmer-productivity of Perl/Python/etc. Yup. That's the jingle. > But if the time that we save writing the app in D will be lost to debugging > simple problems like this then I won't have much of a choice. Hang in there. In my experience, picking up a new language is always a frustrating experience. I think you'll find that D is worth it, though. > > Thanks in advance. > > CHICKZ |
June 18, 2010 Re: ERROR - "cannot implicitly convert expression (s) of type int[3u] to int*" | ||||
---|---|---|---|---|
| ||||
Posted in reply to Chick Corea | Chick Corea wrote: > [NOTE - sent twice as I was unsure that first attempt, > pre-subscription, was received.] > > Working through the basics of D and running into simple problems that I > cannot solve, such as: > > Error: cannot implicitly convert expression (s) of type int[3u] to int* > Error: cannot implicitly convert expression (a) of type int[] to int* > > Those are the result of code that I pulled directly from the D v1 docs from > > http://www.digitalmars.com/d/1.0/arrays.html <snip> This was deprecated in 0.177, but the example code is out of date. http://d.puremagic.com/issues/show_bug.cgi?id=996 Stewart. |
June 18, 2010 Re: ERROR - "cannot implicitly convert expression (s) of type int[3u] to int*" | ||||
---|---|---|---|---|
| ||||
Posted in reply to Chick Corea | On Fri, 18 Jun 2010 01:25:32 -0400, Chick Corea <chick.zcorea@gmail.com> wrote:
> Those are the result of code that I pulled directly from the D v1 docs from
>
> http://www.digitalmars.com/d/1.0/arrays.html
>
> Specifically, the code is this.
>
> int* p;
> int[3] s;
> int[] a;
> p = s;
> p = a;
>
I can't speak as to why the D2 code doesn't work, but this example in the documentation is flat out wrong. To assign a D array to a pointer, you must use the .ptr property, so that the correct code is actually:
int* p;
int[3] s;
int[] a;
p = s.ptr;
p = a.ptr;
Hope this clears things up.
|
June 18, 2010 Re: ERROR - "cannot implicitly convert expression (s) of type int[3u] to int*" | ||||
---|---|---|---|---|
| ||||
Posted in reply to Stewart Gordon | Stewart Gordon wrote:
> Chick Corea wrote:
>> [NOTE - sent twice as I was unsure that first attempt,
>> pre-subscription, was received.]
>>
>> Working through the basics of D and running into simple problems that I
>> cannot solve, such as:
>>
>> Error: cannot implicitly convert expression (s) of type int[3u] to int*
>> Error: cannot implicitly convert expression (a) of type int[] to int*
>>
>> Those are the result of code that I pulled directly from the D v1 docs from
>>
>> http://www.digitalmars.com/d/1.0/arrays.html
> <snip>
>
> This was deprecated in 0.177, but the example code is out of date.
>
> http://d.puremagic.com/issues/show_bug.cgi?id=996
>
> Stewart.
I've just checked in a fix.
|
June 19, 2010 Re: ERROR - "cannot implicitly convert expression (s) of type int[3u] to int*" | ||||
---|---|---|---|---|
| ||||
Posted in reply to Justin Spahr-Summers | On Fri, 18 Jun 2010 08:41:17 -0700, Justin Spahr-Summers <Justin.SpahrSummers@gmail.com> wrote: > > On Fri, 18 Jun 2010 01:25:32 -0400, Chick Corea <chick.zcorea@gmail.com> wrote: > > Those are the result of code that I pulled directly from the D v1 docs from > > > > http://www.digitalmars.com/d/1.0/arrays.html > > > > Specifically, the code is this. > > > > int* p; > > int[3] s; > > int[] a; > > p = s; > > p = a; > > > > I can't speak as to why the D2 code doesn't work, but this example in the documentation is flat out wrong. To assign a D array to a pointer, you must use the .ptr property, so that the correct code is actually: > > int* p; > int[3] s; > int[] a; > p = s.ptr; > p = a.ptr; > > Hope this clears things up. I followed up last night, but my post didn't show up until this morning. Sorry for the redundant answer! :X |
Copyright © 1999-2021 by the D Language Foundation