Declaring array of length 1

T

Tricky

Guest
I have the following array:

subtype level_t is natural range 0 to 4;
type levels_array_t is array(natural range <>) of level_t;

then as a generic I have:

createLevels : levels_array_t := (0, 1, 2, 3);

This is fine when the length of the array is 2 or more, but I when I
try:

createLevels : levels_array_t := (4);
I get the error:
** Error: Integer literal 4 is not of type level_array_t.

How can I declare a literal array of length 1? even trying the
following doesnt work:
createLevels : level_array_t(0 to 0) :=(4);
 
On Fri, 19 Sep 2008 02:37:15 -0700 (PDT), Tricky <Trickyhead@gmail.com>
wrote:

I have the following array:

subtype level_t is natural range 0 to 4;
type levels_array_t is array(natural range <>) of level_t;

then as a generic I have:

createLevels : levels_array_t := (0, 1, 2, 3);
using positional association...

This is fine when the length of the array is 2 or more, but I when I
try:

createLevels : levels_array_t := (4);
Use named association for this
createLevels : levels_array_t := (0 => 4);
or even
createLevels : levels_array_t := (others => 4);

- Brian
 
On Sep 19, 5:37 am, Tricky <Trickyh...@gmail.com> wrote:
I have the following array:

subtype level_t is natural range 0 to 4;
type levels_array_t is array(natural range <>) of level_t;

then as a generic I have:

createLevels  : levels_array_t := (0, 1, 2, 3);

This is fine when the length of the array is 2 or more, but I when I
try:

createLevels : levels_array_t := (4);
I get the error:
** Error: Integer literal 4 is not of type level_array_t.

How can I declare a literal array of length 1? even trying the
following doesnt work:
createLevels                   : level_array_t(0 to 0) :=(4);
Here are two methods...

createLevels2 : levels_array_t := (0=> 4);
createLevels3 : levels_array_t(0 to 0) := (others => 4);

KJ
 
On Sep 19, 8:19 am, Brian Drummond <brian_drumm...@btconnect.com>
wrote:
createLevels : levels_array_t := (0 => 4);
or even
createLevels : levels_array_t := (others => 4);
This ^^ wouldn't work because 'createLevels' is an unconstrained
array.

KJ
 
On Sep 19, 8:19 am, Brian Drummond <brian_drumm...@btconnect.com>
wrote:
or even
createLevels : levels_array_t := (others => 4);

This ^^ wouldn't work because 'createLevels' is an unconstrained
array.

KJ
 
On Fri, 19 Sep 2008 07:25:44 -0700 (PDT), KJ <kkjennings@sbcglobal.net>
wrote:

On Sep 19, 8:19 am, Brian Drummond <brian_drumm...@btconnect.com
wrote:
createLevels : levels_array_t := (0 => 4);
or even
createLevels : levels_array_t := (others => 4);


This ^^ wouldn't work because 'createLevels' is an unconstrained
array.
oops, another brain fart on my part. For a single-element (constrained)
array, it would work. As in your createlevels3 example.
Thanks,

- Brian
 

Welcome to EDABoard.com

Sponsor

Back
Top