| Thread overview | |||||||||
|---|---|---|---|---|---|---|---|---|---|
|
April 25, 2008 implicit conversions between array and pointer | ||||
|---|---|---|---|---|
| ||||
int* p; int[] a=[1,2,3]; p=a; spec says it should compile, but it won't. Where is the bug - in spec or in compiler. | ||||
April 25, 2008 Re: implicit conversions between array and pointer | ||||
|---|---|---|---|---|
| ||||
Posted in reply to terranium | terranium schrieb:
> int* p;
> int[] a=[1,2,3];
> p=a;
>
> spec says it should compile, but it won't. Where is the bug - in spec or in compiler.
In the spec, the implicit convertions to .ptr property was removed some time ago.
p=a.ptr;
| |||
April 25, 2008 Re: implicit conversions between array and pointer | ||||
|---|---|---|---|---|
| ||||
Posted in reply to terranium | On 25/04/2008, terranium <terranium@yandex.ru> wrote:
> int* p;
> int[] a=[1,2,3];
> p=a;
>
> spec says it should compile, but it won't. Where is the bug - in spec or in compiler.
If I had to guess, I'd say the spec is wrong. It's a narrowing conversion. Data is lost. To mind, that means it ought to require an explicit cast.
| |||
April 25, 2008 Re: implicit conversions between array and pointer | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Janice Caron | Hmm... It's ref types, they are casted differently. | |||
April 26, 2008 Re: implicit conversions between array and pointer | ||||
|---|---|---|---|---|
| ||||
Posted in reply to terranium | "terranium" <terranium@yandex.ru> wrote in message news:futcip$peg$1@digitalmars.com... > int* p; > int[] a=[1,2,3]; > p=a; > > spec says it should compile, but it won't. Where is the bug - in spec or in compiler. You must be looking at a terribly out-of-date spec. http://www.digitalmars.com/d/1.0/arrays.html See the "Implicit conversions" section. As was mentioned, implicit conversion from T[] to T* was removed more than a year ago. | |||
April 26, 2008 Re: implicit conversions between array and pointer | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Jarrett Billingsley | > You must be looking at a terribly out-of-date spec.
>
> http://www.digitalmars.com/d/1.0/arrays.html
>
> See the "Implicit conversions" section. As was mentioned, implicit conversion from T[] to T* was removed more than a year ago.
this section is for objects - reference types, I'm talking about value types. Look at sections Usage and Strings.
int* p;
int[3] s;
int[] a;
p = s; // p points to the first element of the array s.
p = a; // p points to the first element of the array a.
char[] str;
char* p = str; // pointer to 1st element
Of course array of ref types can't be converted to pointer to this ref type because D doesn't support pointers to ref types.
| |||
Copyright © 1999-2021 by the D Language Foundation
Permalink
Reply