Declaring array of length 1

Discussion in 'VHDL' started by Tricky, Sep 19, 2008.

  1. Tricky

    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);
     
    Tricky, Sep 19, 2008
    #1
    1. Advertising

  2. Tricky

    Steff

    Joined:
    Sep 8, 2008
    Messages:
    11
    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: Sep 19, 2008
    Steff, Sep 19, 2008
    #2
    1. Advertising

  3. Tricky

    KJ Guest

    On Sep 19, 5:37 am, Tricky <> 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
     
    KJ, Sep 19, 2008
    #3
  4. Tricky

    KJ Guest

    On Sep 19, 8:19 am, Brian Drummond <>
    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
     
    KJ, Sep 19, 2008
    #4
  5. Tricky

    KJ Guest

    On Sep 19, 8:19 am, Brian Drummond <>
    wrote:
    > or even
    > createLevels : levels_array_t := (others => 4);



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

    KJ
     
    KJ, Sep 19, 2008
    #5
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Mitchua
    Replies:
    5
    Views:
    2,809
    Eric J. Roode
    Jul 17, 2003
  2. Replies:
    10
    Views:
    584
    Ian Collins
    Jul 29, 2006
  3. Tom
    Replies:
    3
    Views:
    228
    salsablr
    Dec 20, 2004
  4. Tuan  Bui
    Replies:
    14
    Views:
    507
    it_says_BALLS_on_your forehead
    Jul 29, 2005
  5. sonic
    Replies:
    5
    Views:
    99
Loading...

Share This Page