How to assign data to an unpacked structure?

hi,
i want to assign some data to an unpacked structure using a dynamic array.
i have defined a structure in a file as shown below-

typedef enum {
  RISE,
  FALL
} timing_t;

typedef struct unsigned {
  timing_t timing;
  real min_time; 
} timing_para_t;

In another file i am using this structure where an array is declared of that structure type, in which data will be stored -

timing_para_t timing_db = {
'{RISE, 2},
'{FALL, 1.5}
};

But it is not working. it’s giving error that “Illegal use of “'{” literal for concatenation” and “Illegal concatenation of an unsized constant”.

Please give me suggestions how it will work.

Thanks,
Deepak

You are missing one ’


timing_para_t timing_db[] = '{
'{RISE, 2},
'{FALL, 1.5}
};

With it Questa displays:

dyn_arr: ‘{’{timing:RISE, min_time:2}, '{timing:FALL, min_time:1.5}}

HTH
Ajeetha, CVC

This syntax is illegal. There are some very subtle differences between a concatenation {} and and assignment pattern '{}, both of which can be used to assign an unpacked array. A key requirement in a concatenation is that the types of all items must be self-determined, and '{RISE,2} and '{FALL,1.5} are both assignment patterns without self-determined type. You can make the items self-determined by writing the code as

timing_para_t timing_db[] = { // this is an array concatenation 
                             timing_para_t'{RISE, 2}, // self-determined assignment pattern
                             timing_para_t'{FALL, 1.5}// self-determined assignment pattern
                             };

But there is a simpler solution using an assignment pattern to assign the dynamic array because it uses a context determined type.

timing_para_t timing_db[] = '{ // this is an array assignment pattern
                             '{RISE, 2}, // context determined assignment pattern
                             '{FALL, 1.5}// context determined assignment pattern
                             };

In reply to dave_59:

Thanks Ajeetha and Dave for your suggestions, now it’s working.

one thing i want to ask is that the code i had written(without the tick that you guys suggested) is working properly with VCS without any error or warning but it is giving error in Questa sim. Why is it so?

Thanks,
Deepak

In reply to deepak2407:

Because VCS is not following the rules of the LRM. (See section 10.10 of the 1800-2012 LRM). And in 10.10.1, there is an explicit example showing a similar case that is illegal:

A9 = {A3, '{4,5,6,7,8,9} }; // illegal, '{...} is not self-determined

In your particular case there is no ambiguity in what you are writing, but in general, the LRM does not like to define syntax grammar rules based on the context. As soon as you introduce parametrized types, then it possible the compiler will not understand the syntax of what is written.

In reply to dave_59:

Ok got it thanks