Yunsung Mo
Yunsung Mo

Reputation: 119

Casting (convert) structure to array of bits: bit-stream type error

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

Upvotes: 1

Views: 1381

Answers (1)

dave_59
dave_59

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

Related Questions