Initialization of an unconstrained array object to the null array

Discussion in 'VHDL' started by jens, Aug 18, 2008.

  1. jens

    jens Guest

    On Jun 12 2002, 5:51 pm, (Bill Austin) wrote:
    > Let A be an unconstrained array, e.g.
    > TYPE A is array(natural range <>) or integer.
    > Consider creating objects of type A and initializing them via
    > aggregates:
    >
    > OBJ2 : A := (3, 7); -- Creates a two-element object
    > -- with A(0)=3 and A(1)=7.
    >
    > OBJ1 : A := (0 => 3); -- Creates a one-element object
    > -- with A(0)=3.
    > --(Named association required,
    > -- see e.g. the VHLD FAQ)
    >
    > OBJ0 : A := ? -- how can OBJ0 be initialized
    > -- to anull array?
    >
    > The aggregate syntax (LRM 7.3.2) does not appear to allow for
    > initialization using an aggregate. Can someone confirm this? Anybody
    > have a suggestion for initializing OBJ0 to anull array?


    I'm trying to do the same thing with a default value for a generic.
    It looks like this will do the trick:

    OBJ0 : A := (1 to 0 => 0); -- invalid range results in null array

    However I was hoping to find something that doesn't look like a
    kludge. Any ideas?
    jens, Aug 18, 2008
    #1
    1. Advertising

  2. jens

    sandeep Guest

    On Aug 18, 10:37 am, jens <> wrote:
    > On Jun 12 2002, 5:51 pm, (Bill Austin) wrote:
    >
    >
    >
    >
    >
    > > Let A be an unconstrained array, e.g.
    > >     TYPE A is array(natural range <>) or integer.
    > > Consider creating objects of type A and initializing them via
    > > aggregates:

    >
    > >   OBJ2 : A := (3, 7);   -- Creates a two-element object
    > >                         -- with A(0)=3 and A(1)=7.

    >
    > >   OBJ1 : A := (0 => 3); -- Creates a one-element object
    > >                         -- with A(0)=3.
    > >                         --(Named association required,
    > >                         -- see e.g. the VHLD FAQ)

    >
    > >   OBJ0 : A := ?         -- how can OBJ0 be initialized
    > >                         -- to anull array?

    >
    > > The aggregate syntax (LRM 7.3.2) does not appear to allow for
    > > initialization using an aggregate. Can someone confirm this? Anybody
    > > have a suggestion for initializing OBJ0 to anull array?

    >
    > I'm trying to do the same thing with a default value for a generic.
    > It looks like this will do the trick:
    >
    > OBJ0 : A := (1 to 0 => 0); -- invalid range results in null array
    >
    > However I was hoping to find something that doesn't look like a
    > kludge.  Any ideas?- Hide quoted text -
    >
    > - Show quoted text -


    Can we write
    OBJ0 : A := (others => 0);

    regards
    sandeep, Aug 18, 2008
    #2
    1. Advertising

  3. jens

    Tricky Guest

    On 18 Aug, 03:37, jens <> wrote:
    > On Jun 12 2002, 5:51 pm, (Bill Austin) wrote:
    >
    >
    >
    > > Let A be an unconstrained array, e.g.
    > >     TYPE A is array(natural range <>) or integer.
    > > Consider creating objects of type A and initializing them via
    > > aggregates:

    >
    > >   OBJ2 : A := (3, 7);   -- Creates a two-element object
    > >                         -- with A(0)=3 and A(1)=7.

    >
    > >   OBJ1 : A := (0 => 3); -- Creates a one-element object
    > >                         -- with A(0)=3.
    > >                         --(Named association required,
    > >                         -- see e.g. the VHLD FAQ)

    >
    > >   OBJ0 : A := ?         -- how can OBJ0 be initialized
    > >                         -- to anull array?

    >
    > > The aggregate syntax (LRM 7.3.2) does not appear to allow for
    > > initialization using an aggregate. Can someone confirm this? Anybody
    > > have a suggestion for initializing OBJ0 to anull array?

    >
    > I'm trying to do the same thing with a default value for a generic.
    > It looks like this will do the trick:
    >
    > OBJ0 : A := (1 to 0 => 0); -- invalid range results in null array
    >
    > However I was hoping to find something that doesn't look like a
    > kludge.  Any ideas?



    An invalid range will result in a failed compilation, as well as only
    initialising part of an array. You need to use (others => 0) to make
    sure it is complete. Afaik, the only things that are allowed to be
    null are pointers. An unitialised value will always take the lowest
    value if it is left unassaigned.

    So for example:

    OBJO : A(1 downto 0); will give an array where A(0) and A(1) =
    integer'low.

    For all 0's, just assign (others => 0)

    The example you gave ( OBJ0 : A := (1 to 0 => 0); ) just gives a 2
    element array with both values set to 0. You cannot have an
    unconstrained array in VHDL.

    So the example above: OBJO : A := (others => 0) is invalid because
    there is no range on OBJO.
    Tricky, Aug 18, 2008
    #3
  4. jens

    jens Guest

    Thanks for the info. It's interesting to note that numeric_std uses
    what appears to be a kludge. However that technique doesn't work for
    a generic, as there's a mismatch between the null array length of 0
    and the aggregate length of 1 when there's a non-default value passed
    into the generic. It looks like

    OBJ0 : A := (1 to 0 => 0); -- invalid range results in null array
    or
    OBJ0 : A := (0 downto 1 => 0); -- invalid range results in null array

    may be the only solutions.
    jens, Aug 19, 2008
    #4
    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. FE
    Replies:
    0
    Views:
    1,646
  2. Alex Rast
    Replies:
    3
    Views:
    5,141
    Jim Lewis
    Oct 6, 2003
  3. Victor Hannak
    Replies:
    1
    Views:
    532
    Mike Treseler
    Nov 25, 2003
  4. Replies:
    5
    Views:
    984
    Ralf Hildebrandt
    May 27, 2005
  5. Amal
    Replies:
    5
    Views:
    8,665
    Brandon
    Mar 8, 2006
Loading...

Share This Page