One-element constant array

Discussion in 'VHDL' started by Amal, Oct 19, 2007.

  1. Amal

    Amal Guest

    How does one declare an array constant with only one element?

    type a_t is array(natural range <>) of std_logic_vector(7 downto 0);

    constant a1 : a_t := (
    "00000000"
    );
    constant a2 : a_t := (
    "00000000",
    "00000001"
    );

    a2 passes compiler, but a1 gives error:

    ###### test.vhd(26): "00000000"
    #
    # ** Error: test.vhd(26): String literal found where type a_t, whose
    element type ieee.std_logic_1164.std_logic_vector is not an
    enumeration type, was expected.


    The following works, but is there any other ways?

    constant a1 : a_t := (
    0=> "00000000"
    );

    -- Amal
    Amal, Oct 19, 2007
    #1
    1. Advertising

  2. On Fri, 19 Oct 2007 15:18:44 -0000, Amal <> wrote:

    >How does one declare an array constant with only one element?
    >
    > type a_t is array(natural range <>) of std_logic_vector(7 downto 0);
    >
    > constant a1 : a_t := (
    > "00000000"
    > );
    > constant a2 : a_t := (
    > "00000000",
    > "00000001"
    > );
    >
    >a2 passes compiler, but a1 gives error:
    >
    > ###### test.vhd(26): "00000000"
    > #
    > # ** Error: test.vhd(26): String literal found where type a_t, whose
    >element type ieee.std_logic_1164.std_logic_vector is not an
    >enumeration type, was expected.
    >
    >
    >The following works, but is there any other ways?
    >
    > constant a1 : a_t := (
    > 0=> "00000000"
    > );


    I think the problem is that if your aggregate contains only
    one element, the compiler thinks its parentheses are just
    ordinary parens around an expression and can't work out
    that they're enclosing an aggregate.

    I agree it's tedious, but the named association
    0=>...
    is hardly a big problem.
    --
    Jonathan Bromley, Consultant

    DOULOS - Developing Design Know-how
    VHDL * Verilog * SystemC * e * Perl * Tcl/Tk * Project Services

    Doulos Ltd., 22 Market Place, Ringwood, BH24 1AW, UK

    http://www.MYCOMPANY.com

    The contents of this message may contain personal views which
    are not the views of Doulos Ltd., unless specifically stated.
    Jonathan Bromley, Oct 19, 2007
    #2
    1. Advertising

  3. On Fri, 19 Oct 2007, Jonathan Bromley wrote:

    |-----------------------------------------------------------------------|
    |"On Fri, 19 Oct 2007 15:18:44 -0000, Amal <> wrote:|
    | |
    |>How does one declare an array constant with only one element? |
    |> |
    |> type a_t is array(natural range <>) of std_logic_vector(7 downto 0);|
    |> |
    |> constant a1 : a_t := ( |
    |> "00000000" |
    |> ); |
    |> constant a2 : a_t := ( |
    |> "00000000", |
    |> "00000001" |
    |> ); |
    |> |
    |>a2 passes compiler, but a1 gives error: |
    |> |
    |> ###### test.vhd(26): "00000000" |
    |> # |
    |> # ** Error: test.vhd(26): String literal found where type a_t, whose|
    |>element type ieee.std_logic_1164.std_logic_vector is not an |
    |>enumeration type, was expected. |
    |> |
    |> |
    |>The following works, but is there any other ways? |
    |> |
    |> constant a1 : a_t := ( |
    |> 0=> "00000000" |
    |> ); |
    |" |
    |-----------------------------------------------------------------------|

    No other way exists. See
    4.2.4 Aggregates/Arrays Containing a Single Element
    on
    WWW.VHDL.org/comp.lang.vhdl/FAQ1.html#aggregates

    N.B. This has nothing to do with the reserved word constant.

    |-----------------------------------------------------------------------|
    |"I think the problem is that if your aggregate contains only |
    |one element, the compiler thinks its parentheses are just |
    |ordinary parens around an expression and can't work out |
    |that they're enclosing an aggregate. |
    | |
    |I agree it's tedious, but the named association |
    | 0=>... |
    |is hardly a big problem." |
    |-----------------------------------------------------------------------|

    That is one way of expressing it.

    Regards,
    Colin Paul Gloster
    Colin Paul Gloster, Oct 19, 2007
    #3
    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. Replies:
    13
    Views:
    12,917
    Kai-Uwe Bux
    Jan 22, 2007
  2. HANM
    Replies:
    2
    Views:
    706
    Joseph Kesselman
    Jan 29, 2008
  3. John Koleszar

    address of static array element as address constant

    John Koleszar, Jul 7, 2008, in forum: C Programming
    Replies:
    7
    Views:
    615
    John Koleszar
    Jul 15, 2008
  4. Fredxx
    Replies:
    3
    Views:
    643
    Martin Thompson
    Jul 15, 2009
  5. Rita
    Replies:
    14
    Views:
    163
    Jahagirdar Vijayvithal S
    Dec 5, 2005
Loading...

Share This Page