Skip to content
DenseChip
Learn
PracticeCode labInterview

DenseChip

Navigate

Menu

LearnPracticeCode labInterview

Tools

All toolsSV editorCode repoResume
DenseChip

Practice, courses, and chip-design tools in one focused workspace.

LearnPracticeCode labInterviewToolsLearning paths

© 2026 DenseChip

AboutRoadmapCareersInternshipsFAQContactPrivacyTerms
Skip to lesson

Course contents

  • How to Use This Puzzle Bank
  • SystemVerilog Language Puzzles25
  • Difficulty Guide
  • Full Topic Map
  • Interview-Day Tips
  • Study Route: One Week Before the Interview
  • Study Route: Two Weeks
  • Study Route: Four Weeks (Full Course)4
  • OOP & Testbench Puzzles25
    • Handle and Copy Puzzles
    • Virtual Method Puzzles
    • Parameterized Class Puzzles
      • Global Static vs Per-Specialization Static
      • Same Specialization via typedef Alias
      • $cast Between Specializations via a Common Base
      • Unrelated Specializations Cannot Be Assigned
      • Static Function Counters Per Specialization
      • Wrong UVM Macro for Parameterized Object
    • Factory Override Puzzles
    • OOP & Testbench Puzzles: Tricky Q&A
  • Concurrency & Timing Puzzles25
  • Randomization & Constraint Puzzles25
  • SVA Assertion Puzzles25
  • Functional Coverage Puzzles25
  • Logic & Aptitude Puzzles25
  • Scenario & Debug Puzzles25
  • UVM Testbench Puzzles25
  • Clock, Reset & CDC Puzzles25
  • Bus and Interface Protocol Puzzles25
  • Interview Prep: Puzzle Rounds7
  • DV Puzzle Cheatsheet
Loading lesson

←Parameterized Class Puzzles
  1. Topics
  2. DV Interview Puzzles
  3. OOP & Testbench Puzzles
  4. Parameterized Class Puzzles
  5. Same Specialization via typedef Alias
On this page

    VLSI DV Interview PuzzlesAll levels

    Same Specialization via typedef Alias

    Do these two handles share the same static counter or maintain two counters?

    Puzzle

    Difficulty: Medium · Puzzle 2 of 6 · Topic: Parameterized Class Puzzles

    Do these two handles share the same static counter or maintain two counters?

    Code

    design.sv
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    class pkt #(int W = 8);
      static int created = 0;
      function new();
        created++;
      endfunction
    endclass
    
    typedef pkt#(32) pkt32_t;
    
    initial begin
      pkt#(32) a;
      pkt32_t  b;
      a = new();
      b = new();
      $display("pkt#(32)::created=%0d", pkt#(32)::created);
      $display("pkt32_t::created=%0d", pkt32_t::created);
    end

    Hint

    A typedef alias does not create a new specialization.

    Step-by-step solution

    Diagram
    1) `pkt32_t` is only an alias for exactly `pkt#(32)`.
    2) Both objects increment the same specialization static `created`.
    3) Both displays print 2.

    Answer

    Answer: They share one counter; both lines print 2 because typedef alias points to same specialization.

    How this was checked

    Checked by running the code in Verilator 5; the printed output supports the answer above. The shown code run in Verilator: a typedef alias is the same specialization and shares one static.

    Why candidates get it wrong

    Mistaking typedef for a new derived type causes wrong assumptions about static sharing. Note the construction is written as separate statements inside `initial`: with declaration initialisers (`pkt#(32) a = new();`) the order of those initialisers against the class static `created = 0` is not fixed by the LRM, and Verilator 5.048 printed `0 0` for that form. Assigning `a = new(); b = new();` in the body gives 2 and 2 in every tool.

    Interviewer follow-up

    Would `pkt#(16)::created` change in this snippet? Model answer: no, it stays 0. `pkt#(16)` is a different specialization with its own static, and no `pkt#(16)` object was constructed.

    Say it out loud

    They share one counter, and both lines print 2. A typedef is only an alias for the same specialization, so there is only one class and one static created variable. The trap is thinking the alias creates a separate type. I would check that the parameter values are identical, because only identical values give the same specialization.

    Related topics

    • Parameterized Classes

    • Static Properties & Methods

    • Back to Parameterized Class Puzzles

    • OOP & Testbench Puzzles section

    Previous

    49 / 293

    Next: $cast Between Specializations via a Common Base

    Up next

    Up next$cast Between Specializations via a Common Base

    Sign in to save progress

    Practice this lessonPrevious lessonReport an error

    See also

    • Unrelated Specializations Cannot Be Assigned
    • Static Function Counters Per Specialization
    • Wrong UVM Macro for Parameterized Object