can I have unconstrained String as record element?

T

Tricky

Guest
Can I do what I asked, I suspect not, so Im thinking along the lines:

type my_record_type is
record
name : string(1 to 20);
....
end record my_record;

Basically, I want to be able to give the record name a constant string
when it is delcared like:

CONSTANT my_record : my_record_type := ( name => "Betty Swollocks",
--length only 15, complains unless I pad to 20 chars.
.......)

Or am I just going to have to pad the name with whitespace to make it
up to name'length?
 
On Jun 24, 11:48 am, Tricky <Trickyh...@gmail.com> wrote:
Can I do what I asked, I suspect not, so Im thinking along the lines:
You suspect correctly, you can not have an unconstrained vector of any
type as a record element.

Basically, I want to be able to give the record name a constant string
when it is delcared like:

CONSTANT my_record : my_record_type := ( name => "Betty Swollocks",
--length only 15, complains unless I pad to 20 chars.
                                                                      .......)

Or am I just going to have to pad the name with whitespace to make it
up to name'length?
A cleaner way than simply typing in the extra whitespace is to define
a function that pads on the appropriate spaces and put that in the
same package where 'my_type' is defined.

function Padder(s: string) return string is
variable s0: string(1 to s'length) := s;
variable RetVal: string(my_record_type.name'range);
begin
RetVal := (others => ' ');
RetVal(s0'range) := s0;
...
end function Padder;

That way you can initialize constants like this...
CONSTANT my_record : my_record_type := ( name => Padder("Betty
Swollocks"),...

KJ
 
On Jun 24, 11:48 am, Tricky <Trickyh...@gmail.com> wrote:
Can I do what I asked, I suspect not, so Im thinking along the lines:

type my_record_type is
  record
    name    : string(1 to 20);
    ....
  end record my_record;

Basically, I want to be able to give the record name a constant string
when it is delcared like:

CONSTANT my_record : my_record_type := ( name => "Betty Swollocks",
--length only 15, complains unless I pad to 20 chars.
                                                                      .......)

Or am I just going to have to pad the name with whitespace to make it
up to name'length?
If you want variable length strings you can use an access type to
define a string pointer.

eg: type string_ptr is access string;

Your record would look something like this:

type my_record_type is
record
name : string_ptr;
....
end record my_record;

To set the string you use the "new" keyword to allocate memory.

my_record.name <= new string'("Betty Swollocks");

When you are done using my_record.name, you deallocate the memory
using the deallocate procedure.

Read up on access types.
 
On Jun 24, 1:27 pm, Andrew <sharp...@gmail.com> wrote:
On Jun 24, 11:48 am, Tricky <Trickyh...@gmail.com> wrote:





Can I do what I asked, I suspect not, so Im thinking along the lines:

type my_record_type is
  record
    name    : string(1 to 20);
    ....
  end record my_record;

Basically, I want to be able to give the record name a constant string
when it is delcared like:

CONSTANT my_record : my_record_type := ( name => "Betty Swollocks",
--length only 15, complains unless I pad to 20 chars.
                                                                      ........)

Or am I just going to have to pad the name with whitespace to make it
up to name'length?

If you want variable length strings you can use an access type to
define a string pointer.

eg: type string_ptr is access string;

Your record would look something like this:

type my_record_type is
  record
    name    : string_ptr;
    ....
  end record my_record;

To set the string you use the "new" keyword to allocate memory.

my_record.name <= new string'("Betty Swollocks");

When you are done using my_record.name, you deallocate the memory
using the deallocate procedure.

Read up on access types.- Hide quoted text -

- Show quoted text -
Can a record containing access types be an entity port?
 
On Jun 24, 7:07 pm, Reuven <rpaley...@gmail.com> wrote:
On Jun 24, 1:27 pm, Andrew <sharp...@gmail.com> wrote:



On Jun 24, 11:48 am, Tricky <Trickyh...@gmail.com> wrote:

Can I do what I asked, I suspect not, so Im thinking along the lines:

type my_record_type is
  record
    name    : string(1 to 20);
    ....
  end record my_record;

Basically, I want to be able to give the record name a constant string
when it is delcared like:

CONSTANT my_record : my_record_type := ( name => "Betty Swollocks",
--length only 15, complains unless I pad to 20 chars.
                                                                      ........)

Or am I just going to have to pad the name with whitespace to make it
up to name'length?

If you want variable length strings you can use an access type to
define a string pointer.

eg: type string_ptr is access string;

Your record would look something like this:

type my_record_type is
  record
    name    : string_ptr;
    ....
  end record my_record;

To set the string you use the "new" keyword to allocate memory.

my_record.name <= new string'("Betty Swollocks");

When you are done using my_record.name, you deallocate the memory
using the deallocate procedure.

Read up on access types.- Hide quoted text -

- Show quoted text -

Can a record containing access types be an entity port?
I don't think so... Signals and constants can't be declared as access
types. Access types are not synthesizable but they are incredibly
useful for testbenches.
 

Welcome to EDABoard.com

Sponsor

Back
Top