www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - array to pointer conversion

reply mario pernici <mario.pernici mi.infn.it> writes:
Hello,

the following example does not compile with dmd 1.05:

void main()
{
  int* p;
  int[3] s;
  for(int i=0; i < 3; i++) s[i] = i;
  p = s;
}

bug1.d(6): Error: cannot implicitly convert expression (s) of type int[3] to
int*

while it seems it should according to the spec (Array Declaration).
It used to work in some previous version of dmd.

The following works with dmd 1.05:
p = cast(int*) s;


Mario
Feb 11 2007
parent Sean Kelly <sean f4.ca> writes:
mario pernici wrote:
 Hello,
 
 the following example does not compile with dmd 1.05:
 
 void main()
 {
   int* p;
   int[3] s;
   for(int i=0; i < 3; i++) s[i] = i;
   p = s;
 }
 
 bug1.d(6): Error: cannot implicitly convert expression (s) of type int[3] to
int*
 
 while it seems it should according to the spec (Array Declaration).
 It used to work in some previous version of dmd.
 
 The following works with dmd 1.05:
 p = cast(int*) s;
Try "p = s.ptr" The implicit conversion was made illegal a while back. You may want to submit a bug report for the docs if they don't mention this. Sean
Feb 11 2007