2

How can we initialize a queue of structure with replication when non-replicated elements are also present? I tried out below ways without success. Is it even possible?

typedef struct {
 A a;
 B b;
 C c;
 D d;
} lp_s;    //A,B,C,D : integer enums

lp_s var_name[$] = '{    
     '{a: A_VAL0, b: B_VAL1, default:0}
'{15{'{a: A_VAL1, b: B_VAL1, default:0}}},
     '{a: A_VAL2, b: B_VAL2, default:0}
};

Error here is :

Assignment pattern is illegal due to: Replication field exceeds the size of the target

I removed the tick from replication.

lp_s var_name[$] = '{    
         '{a: A_VAL0, b: B_VAL1, default:0}
     {15{'{a: A_VAL1, b: B_VAL1, default:0}}},
         '{a: A_VAL2, b: B_VAL2, default:0}
    };

Then error became:

Unpacked Structure of type 'lp_s' can't be assigned by multiple
concatenation operator {15 {'{a: A_VAL1, b: B_VAL1, default:0}}}
However assignment pattern can be assigned to unpacked structures. Add a ' before concatenation operator to convert it to a valid assignment pattern.

Or is there a way to achieve using unpacked array concatenation?

1 Answer 1

5

You can add an explicit type to an assignment pattern so it can be used in a self-determined context.

typedef lp_s lp_sq[$];

lp_s vari[$] = { // unpacked array concatenation of struct assignment patterns
                lp_s'{a: A_ENUM, b: B_ENUM, C: J_ENUM, D: D_ENUM},
               lp_sq'{12{lp_s'{a: A_ENUM, b: B_ENUM, C: J_ENUM, D: D_ENUM}}},
                lp_s'{a: A_ENUM, b: B_ENUM, C: J_ENUM, D: D_ENUM }
};

Note, you can't use default:0 here because 0 is not a valid value type to assign to an enum.

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

Comments

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.