1

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
  • First, for $bits() function, compiler says the argument of the system function call was not of bit-stream type.
  • Second, when assign 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
    My understanding is that, structure and unpacked array are also bit-stream type.
    Hope to know what is a point I missed.(cadence 18.09-006)
Giampietro Seu
  • 786
  • 9
  • 16
Yunsung Mo
  • 89
  • 1
  • 6

1 Answers1

2

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.

dave_59
  • 39,096
  • 3
  • 24
  • 63
  • Yes, in LRM, there is what you answer but for above example, there is also description that “The size of union in bits is the size of its largest member”. – Yunsung Mo Aug 05 '19 at 04:22
  • This is a reported problem example with the LRM. A real/shortreal is not a bit-stream type, and therefore cannot be used with $bits. – dave_59 Aug 05 '19 at 16:07