system verilog - systemverilog cast peculiarity -


my question regarding using $cast in sv. if search word cast in code below, have on purpose added '!' check unsuccessful casting. in event of unsuccessful cast, wanted see happens when call made bobsquare.bob(); surprised @ time=1ms when call_bob called handle polygon 'p', function 'bob' in square class called perform display statements. how can possible? ran cadence's irun , debugged sv class browser , see @ time=1ms, bobsquare not allocated mem space , has null pointer. thanks!

class figure;  endclass  class polygon extends figure;    virtual function void draw();     $display("polygon::draw");   endfunction  endclass  class square extends polygon;    virtual function void draw();     $display("square::draw");   endfunction    function void compute_area();     $display("square::compute_area");   endfunction    function void bob();      $display("square::i bob");      $display("%t", $realtime);        endfunction  endclass  program top;   polygon p;   square s;    initial begin     s = new();     p = new();       #1ms;      call_bob(p);      #1ms;      call_bob(s);        end // initial begin    task call_bob(figure generic_ref_figure);       square bobsquare;             if (!($cast(bobsquare, generic_ref_figure)))          bobsquare.bob();    endtask // call_bob  endprogram 

ieee std 1800-2012 § 8.4 (& ieee std 1800-2005 § 7.4) states:

accessing non-static members (see 8.9) or virtual methods (see 8.20) via null object handle illegal. result of illegal access via null object indeterminate, , implementations may issue error.

i unable find reference on should happen default method type. based on lrm, appeares calling non-virtual methods via null object handle legal long method not calling non-static members.

make method bob virtual null object handle error.


Comments

Popular posts from this blog

javascript - DIV "hiding" when changing dropdown value -

Does Firefox offer AppleScript support to get URL of windows? -

android - How to install packaged app on Firefox for mobile? -