struct packed {
int a;
int b;
int c;
int d; … till int z;
} a2z_struct;
To access the structure’s element I can use hierarchical way like a2z_struct.a = 0;
But If I want to use indexing way, meaning this structure has 26 members. Lets say I want to access 24th member.
How Can I do that? a2z_struct[24] = 1 ( Not working)
You have a packed struct with 26 integer. So the total size of the packed vector is 26*32 bits.
These are packed from a to z where the 32 bits of a are in the MSB and the 32 bit of z are in the LSB position.
If you want to change the value of member y to 22 , try a2z_struct[63:32] = 22;
You can use a packed union to access a structure a number of different ways.
union packed {
struct packed {
int a;
int b;
int c;
int d; ..... till int z;
} as_struct;
bit [1:26] [31:0] as_array;
} a2z;
Then a2z.as_struct.x and a2z.as_array[24] refer too the same set of 32-bits. Note that when you define an array, each element has to be the same type/width. In this case it only works if all members of packed struct are the same width.