Declaring array of length 1

T

Tricky

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);
 
Joined
Sep 8, 2008
Messages
11
Reaction score
0
Hy,

it is of course possible having an array length of 1, but you have to map the value by (index) name not by position. Therefore you must write:

createLevels : levels_array_t(0 to 0) := (0 => 4);

Thats all.

Hope I could help you!

Bye, Steff
 
Last edited:
K

KJ

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
 
K

KJ

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top