www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Array Initialization

reply Daniel Keep <daniel.keep(at)gmail(.)com> <Daniel_member pathlink.com> writes:
(n00bie alert--think Star Trek-style klaxxons)

Hi.  I'm new here.

I was wondering about array initialization under D.  Currently, I'm trying the
following:

int[] stuff = [1,2,3,4];

Which doesn't work since stuff isn't static.  My first question is, why can't it
just infer the size for me?  ``char[] abc = "abc";'' works, so why not
(basically) the same expression with int's instead?

I also noticed that ``char[] abc; abc = "abc";'' also works, but once again,
change "char" to "int", and the compiler borks.

Have I hit a bug, or is there a good reason it's like this?

Thanks for your time,

-- Daniel

"A cache without a proper policy isn’t a cache it’s a memory leak."
        -- Rico Mariani
Oct 26 2004
parent Derek Parnell <derek psych.ward> writes:
On Wed, 27 Oct 2004 01:21:04 +0000 (UTC), Daniel Keepatgmail.com> wrote:

 (n00bie alert--think Star Trek-style klaxxons)
 
 Hi.  I'm new here.
 
 I was wondering about array initialization under D.  Currently, I'm trying the
 following:
 
 int[] stuff = [1,2,3,4];
 
 Which doesn't work since stuff isn't static.  My first question is, why can't
it
 just infer the size for me?  ``char[] abc = "abc";'' works, so why not
 (basically) the same expression with int's instead?
 
 I also noticed that ``char[] abc; abc = "abc";'' also works, but once again,
 change "char" to "int", and the compiler borks.
 
 Have I hit a bug, or is there a good reason it's like this?
 
Some have called it a bug, and others have suggested that it just has been implemented yet. Anyhow, this limitation has been promised to be lifted in some future release. -- Derek Melbourne, Australia 27/10/2004 12:56:40 PM
Oct 26 2004