VLSI DV Interview Puzzles · All levels
Integral Parameter Specializations Split Statics
A class is parameterized by depth. Predict statics for depth 8 vs depth 16.
Puzzle
Difficulty: Easy · Puzzle 3 of 6 · Topic: Parameterized Class Puzzles
A class is parameterized by depth. Predict statics for depth 8 vs depth 16.
Code
systemverilog
class fifo_cfg #(int DEPTH = 8);
static int instances = 0;
function new();
instances++;
endfunction
endclass
initial begin
fifo_cfg#(8) a = new();
fifo_cfg#(8) b = new();
fifo_cfg#(16) c = new();
$display("d8=%0d d16=%0d", fifo_cfg#(8)::instances, fifo_cfg#(16)::instances);
endHint
Each unique parameter value forms a different specialization type.
Step-by-step solution
diagram
1) Two objects are created for specialization `fifo_cfg#(8)` => its static is 2.
2) One object is created for specialization `fifo_cfg#(16)` => its static is 1.
3) Statics are independent because specializations are distinct types.Answer
Answer: Output is `d8=2 d16=1`.
Why candidates get it wrong
People sometimes assume all integer-parameter variants share one static namespace.
Interviewer follow-up
How would you create one truly global instance counter for all DEPTH values?