Initialization of an unconstrained array object to the null array

This is a discussion on Initialization of an unconstrained array object to the null array within the vhdl forums in Programming Languages category; On Jun 12 2002, 5:51 pm, b...@altavista.com (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 ...

Go Back   Application Development Forum > Programming Languages > vhdl

Object Mix

Register FAQ Calendar Search Today's Posts Mark Forums Read
  #1  
Old 08-17-2008, 10:37 PM
jens
Guest
 
Default Initialization of an unconstrained array object to the null array

On Jun 12 2002, 5:51 pm, b...@altavista.com (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?
Reply With Quote
  #2  
Old 08-18-2008, 04:09 AM
sandeep
Guest
 
Default Re: Initialization of an unconstrained array object to the null array

On Aug 18, 10:37*am, jens <ro...@rochester.rr.com> wrote:
> On Jun 12 2002, 5:51 pm, b...@altavista.com (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

Reply With Quote
  #3  
Old 08-18-2008, 04:45 AM
Tricky
Guest
 
Default Re: Initialization of an unconstrained array object to the null array

On 18 Aug, 03:37, jens <ro...@rochester.rr.com> wrote:
> On Jun 12 2002, 5:51 pm, b...@altavista.com (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.
Reply With Quote
  #4  
Old 08-18-2008, 04:54 AM
Alan Fitch
Guest
 
Default Re: Initialization of an unconstrained array object to the null array

Tricky wrote:
> On 18 Aug, 03:37, jens <ro...@rochester.rr.com> wrote:
>> On Jun 12 2002, 5:51 pm, b...@altavista.com (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.


There are some null arrays declared in Numeric std - it's done like this:

constant NAU: UNSIGNED(0 downto 1) := (others => '0');

i.e. by using an invalid range initialised by an aggregated.

So you should be able to do


ojb0 : a(1 downto 0) := (others => '0');

regards
Alan
Reply With Quote
  #5  
Old 08-18-2008, 05:36 AM
Alan Fitch
Guest
 
Default Re: Initialization of an unconstrained array object to the null array

Alan Fitch wrote:
> Tricky wrote:
>> On 18 Aug, 03:37, jens <ro...@rochester.rr.com> wrote:
>>> On Jun 12 2002, 5:51 pm, b...@altavista.com (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

<snip>

>
> There are some null arrays declared in Numeric std - it's done like this:
>
> constant NAU: UNSIGNED(0 downto 1) := (others => '0');
>
> i.e. by using an invalid range initialised by an aggregated.
>
> So you should be able to do
>
>
> ojb0 : a(1 downto 0) := (others => '0');
>
> regards
> Alan


Oops, of course I meant

ojb0 : a(0 downto 1) := (others => '0');

Alan
--
Alan Fitch
Doulos
http://www.doulos.com
Reply With Quote
  #6  
Old 08-18-2008, 10:29 PM
jens
Guest
 
Default Re: Initialization of an unconstrained array object to the null array

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.
Reply With Quote
  #7  
Old 08-19-2008, 07:32 AM
jens
Guest
 
Default Re: Initialization of an unconstrained array object to the null array

On Aug 18, 10:29*pm, jens <ro...@rochester.rr.com> wrote:
> 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.


Oops, cancel that. It seemed to work fine in ModelSim but ISE 10.1
doesn't like it - it issues a warning about the null range array just
like ModelSim does, but then it goes ahead and creates a two-element
array anyway. Depending on what the LRM says this may be a tool
issue. So at this point I don't have a solution, I'll probably have
to have the default value be a single element array that's out of the
range of any anticipated constrained array and then use if ...
generate to ignore that value.
Reply With Quote
Reply


Thread Tools
Display Modes


All times are GMT -5. The time now is 11:53 PM.


Powered by vBulletin® Version 3.7.2
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0
vB Ad Management by =RedTyger=

In an effort to better serve ads to our visitors, cookies are used on objectmix.com. For more information, check out our Privacy Policy.