2

I can write:

type bit2_t is array (0 to 1) of bit;
type record0 is record
    bit2 : bit2_t;
end record;

But I'd like to do it without defining bit2_t since I don't need it, something like:

type record0 is record
    bit2 : array (0 to 1) of bit;
end record;

But if I try that, GHDL 0.34 says:

type mark expected in a subtype indication

1 Answer 1

0

You are simply declaring the array instance incorrectly. Instead of

type bit2_t is array (0 to 1) of bit;
type record0 is record
  bit2 : array (0 to 1) of bit;
end record;

You need to use

type bit2_t is array (integer range <>) of bit;
type record0 is record
  bit2 : bit2_t(0 to 1);
end record;

If you wanted an array of 2-bit arrays of bits, you would use

type bit2_t is array (0 to 1) of bit;
type bit2_array_t is array (integer range <>) of bit2_t;
type record0 is record
  bit2 : bit2_array_t(0 to 7);  -- '7' or whatever your range needs to be
end record;

You could make this slightly more generic by changing the 7 to a constant, something like bit2 : bit2_array_t(0 to BIT2_ARRAY_LENGTH-1);.

If you want to have a record type that is in some way paramatized, as far as I know you can only achieve this using package generics, as explained in this answer. Your code would use the package as described, and this package would declare your record type with array sizes based on a generic parameter. By instantiating the package with a different value for the generic in each case, your record could have different element sizes for these different cases.

I would note that I do not believe package generics are widely supported by synthesis tools.

Sign up to request clarification or add additional context in comments.

5 Comments

I don't quite understand, your second example still defines the bit2_t type, which is what I'd like to avoid.
@CiroSantilli巴拿馬文件六四事件法轮功 Hm, I don't understand what you're asking for in that case, sorry. It sounds like you want to define a record type without predefining the type of one of its elements? If so I'm not sure that is possible.
Yup that's it. Just to write less. Like we can do in C.
@CiroSantilli巴拿馬文件六四事件法轮功 It's not possible.
@CiroSantilli巴拿馬文件六四事件法轮功 I updated my answer linking to another existing answer, maybe that helps? I didn't see much point in copying code from that answer into mine.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.