www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Copying int[] from dynamic to static arrays?

reply AEon <aeon2001 lycos.de> writes:
I have a global static array called

	int[6] UTtime;

and a function that returns a dynamic array (also with 6 elements):

	int[] dt = convert_Dtime_to_Digits( myTimeUT );

but:

	UTtime = convert_Dtime_to_Digits( myTimeUT );

will not compile, since there is a conflict between the static and 
dynamic arrays, even though they have the same size. That is to be expected.

So is the below:

	foreach( int i, int datetime; UTtime )
		UTtime[i] = datetime;

the only way to copy the data? Or is there some other D shortcut to copy 
the data between arrays?

AEon
Mar 29 2005
parent Derek Parnell <derek psych.ward> writes:
On Wed, 30 Mar 2005 04:32:14 +0200, AEon wrote:

 I have a global static array called
 
 	int[6] UTtime;
 
 and a function that returns a dynamic array (also with 6 elements):
 
 	int[] dt = convert_Dtime_to_Digits( myTimeUT );
 
 but:
 
 	UTtime = convert_Dtime_to_Digits( myTimeUT );
 
 will not compile, since there is a conflict between the static and 
 dynamic arrays, even though they have the same size. That is to be expected.
 
 So is the below:
 
 	foreach( int i, int datetime; UTtime )
 		UTtime[i] = datetime;
 
 the only way to copy the data? Or is there some other D shortcut to copy 
 the data between arrays?
The syntax to use in this case is ... UTtime[] = convert_Dtime_to_Digits( myTimeUT ); But the function *must* return exactly the same length as the fixed array length. -- Derek Melbourne, Australia 30/03/2005 12:43:10 PM
Mar 29 2005