Cliff, Kudos to you for no syntax errors! Here is the output I get: # BasePacket::A is 1 # BasePacket::B is 2 # BasePacket::C is 3 # BasePacket::A is 1 # MyPacket1::B is 5 # MyPacket1::C is 6 # MyPacket1::A is 4 # MyPacket1::B is 5 # MyPacket1::C is 6 # BasePacket::A is 1 # ExtPacket::B is 8 # MyPacket1::C is 6 # MyPacket1::A is 4 # ExtPacket::B is 8 # MyPacket1::C is 6 // You thought 9 # ExtPacket::A is 7 # ExtPacket::B is 8 # MyPacket1::C is 6 // You thought 9 The reason is that you did not define a virtual method in ExtPacket so you are getting the Mypacket. The confusion you may be having is that a method may be virtual, but class properties are never virtual. A method uses its normal class hierarchy search rules for properties whether the method is virtual or not; i.e. making a method *virtual* does not change the search rules for properties. Since Mypacket::printC is defined in Mypacket, it will start it's search there and find it there. Had you not overridden it in Mypacket, it would go up to find it in the parent BasePacket. By always accessing a property via a virtual method, you get the effect of a virtual property. Dave > -----Original Message----- > From: owner-sv-ec@eda.org [mailto:owner-sv-ec@eda.org] On Behalf Of > Clifford E. Cummings > Sent: Tuesday, March 28, 2006 1:17 PM > To: sv-ec@eda.org > Subject: [sv-ec] Cliff's 1308 email No-vote - See attached example > > Cliff votes NO on the 1308 proposal as is. Friendly(?) amendments > pending (to be proposed by Cliff) > > Reason - not yet clear enough. I will propose additional > clarifications to Dave's greatly-improved-wording after I understand > the following example. In the following example, there are two levels > of extension and an interesting mixture of virtual and non-virtual > methods. Please examine the (untested) example (shown below and > attached) and let me know if my reasoning is correct or not. The > output lines with ??? are where I am most unsure. > > Regards - Cliff > > module virtualmenthods; > //------------------------------------------------------------- > class BasePacket; > int A = 1; > int B = 2; > int C = 3; > > function void printA; > $display("BasePacket::A is %d",A); > endfunction : printA > > virtual function void printB; > $display("BasePacket::B is %d",B); > endfunction : printB > > virtual function void printC; > $display("BasePacket::C is %d",C); > endfunction : printC > endclass : BasePacket > //------------------------------------------------------------- > class MyPacket1 extends BasePacket; > int A = 4; > int B = 5; > int C = 6; > > function void printA; > $display("MyPacket1::A is %d",A); > endfunction : printA > > function void printB; > $display("MyPacket1::B is %d",B); > endfunction : printB > > virtual function void printC; > $display("MyPacket1::C is %d",C); > endfunction : printC > endclass : MyPacket1 > //------------------------------------------------------------- > class ExtPacket extends MyPacket1; > int A = 7; > int B = 8; > int C = 9; > > function void printA; > $display("ExtPacket::A is %d",A); > endfunction : printA > > virtual function void printB; > $display("ExtPacket::B is %d",B); > endfunction : printB > > // No printC function in ExtPacket > // Inherit printC from MyPacket1 > endclass : ExtPacket > //------------------------------------------------------------- > > BasePacket P1 = new; > MyPacket1 P2 = new; > ExtPacket P3 = new; > > initial begin > P1.printA; // displays 'BasePacket::A is 1' > P1.printB; // displays 'BasePacket::B is 2' > P1.printC; // displays 'BasePacket::C is 3' > //----------------------------------------------------------- > P1 = P2; // P1 has a handle to a MyPacket1 object > > P1.printA; // displays 'BasePacket::A is 1' > P1.printB; // displays 'MyPacket1::B is 5' - latest derived method > P1.printC; // displays 'MyPacket1::C is 6' - latest derived method > > P2.printA; // displays 'MyPacket1::A is 4' > P2.printB; // displays 'MyPacket1::B is 5' > P2.printC; // displays 'MyPacket1::C is 6' > //----------------------------------------------------------- > P1 = P3; // P1 has a handle to an ExtPacket object > P2 = P3; // P2 has a handle to an ExtPacket object > > P1.printA; // displays 'BasePacket::A is 1' > P1.printB; // displays 'ExtPacket::B is 8' - ??? > P1.printC; // displays 'MyPacket1::C is 9' - ??? > > P2.printA; // displays 'MyPacket1::A is 4' > P2.printB; // displays 'ExtPacket::B is 8' - ??? (virtual again???) > P2.printC; // displays 'MyPacket1::C is 9' - ??? (9???) > > P3.printA; // displays 'ExtPacket::A is 7' > P3.printB; // displays 'ExtPacket::B is 8' > P3.printC; // displays 'MyPacket1::C is 9' - ??? (9???) > //----------------------------------------------------------- > end > endmodule > > > > ---------------------------------------------------- > Cliff Cummings - Sunburst Design, Inc. > 14314 SW Allen Blvd., PMB 501, Beaverton, OR 97005 > Phone: 503-641-8446 / FAX: 503-641-8486 > cliffc@sunburst-design.com / www.sunburst-design.com > Expert Verilog, SystemVerilog, Synthesis and Verification TrainingReceived on Tue Mar 28 14:01:25 2006
This archive was generated by hypermail 2.1.8 : Tue Mar 28 2006 - 14:01:29 PST