Reputation: 119
In systemverilog LRM
, there is a sample code to explain casting.
When I try this code, there is an error.
typedef struct {
bit isfloat;
union { int i; shortreal f; } n; // anonymous type
} tagged_st; // named structure
typedef bit [$bits(tagged_st) - 1 : 0] tagbits;
tagged_st a [7:0]; // unpacked array of structures
tagbits t = tagbits'(a[3]); / convert structure to array of bits
a[4] = tagged_st'(t); // convert array of bits back to structure
$bits()
function, compiler says the argument of the system function call was not of bit-stream type.
a[3]
with a type casting of tagbits
, it says The source of the target of the bit-stream casting is not of bit-stream type
(cadence 18.09-006)
Upvotes: 1
Views: 1381
Reputation: 42698
An unpacked union is not a bitstream type. From the LRM,
By default, a union is unpacked, meaning there is no required representation for how members of the union are stored
This means you cannot know how many bits are represented.
Upvotes: 2