SystemVerilog OOP Mastery · All levels
Specializations, typedef Aliases, and the Per-Specialization Static Gotcha: Concept Explained
Concept Explained for Specializations, typedef Aliases, and the Per-Specialization Static Gotcha.
Concept
In short: Each unique parameter combination creates a distinct class specialization, and each specialization owns its own static storage.
The most common bug in this topic is assuming one global static variable across all specializations. In reality, packet#(bit[7:0],16)::created and packet#(int,4)::created are independent storage locations because they belong to different specialized classes.
typedef does not merge or alias storage between different parameter sets; it only gives a name to one exact specialization. Use typedef for readability, but design your counters deliberately: per-specialization counters when that is intended, or an external shared class/package variable if you need one truly global count.