<p>In E (specman) I want to declare variables that are lists, and I want to fix their lengths.</p>

<p>It's easy to do for a member of a struct:</p>

<pre><code>thread[2] : list of thread_t;
</code></pre>

<p>while for a "regular" variable in a function the above doesn't work, and I have to do something like:</p>

<pre><code>var warned : list of bool;
gen warned keeping {
    it.size() == 5;
};
</code></pre>

<p>Is there a better way to declare a list of fixed size?</p>

[{'answer_id': 28801, 'author': 'Joel Coehoorn', 'author_id': 3043, 'author_profile': 'https://Stackoverflow.com/users/3043', 'pm_score': -1, 'selected': False, 'text': '<p>I know nothing of specman, but a fixed sized list is an array, so that might point you somewhere.</p>\n'}, {'answer_id': 37438, 'author': 'JawnV6', 'author_id': 3869, 'author_profile': 'https://Stackoverflow.com/users/3869', 'pm_score': 3, 'selected': True, 'text': "<p>A hard keep like you have is only going to fix the size at initialization but elements could still be added or dropped later, are you trying to guard against this condition?  The only way I can think of to guarantee that elements aren't added or dropped later is emitting an event synced on the size != the predetermined amount:</p>\n\n<pre><code>event list_size_changed is true (wanted.size() != 5) @clk;\n</code></pre>\n\n<p>The only other thing that I can offer is a bit of syntactic sugar for the hard keep:</p>\n\n<pre><code>var warned : list of bool;\nkeep warned.size() == 5;\n</code></pre>\n"}]
['https://Stackoverflow.com/questions/20696', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/1084/']