[sv-bc] operators and data type compatibility rules

From: Francoise Martinolle <fm_at_.....>
Date: Fri Sep 15 2006 - 07:25:13 PDT
Can you use logical equality and inequality for class handles which are
not of the same class hierarchy or which are
in the same class hierarchy but different derived classes?
 
Ex:
 
class A;
endclass
 
A a;
 
class B;
endclass
 
class C extends B;
endclass
 
C c, c1;
B b, b1;
 
initial begin
  a = new;
  b = new;
  b1 = new;
  c = new;
  c1 = new;
 
  if (a == b)
    ...
 
  if (b == c)
     ....
 
     
  if (b == b1)  // this is for sure allowed
     ...
 
  if ( b == null) // this is also allowed
 
 
 
end
 
My opinion is that only class handles of the same class data type can be
compared.
 
Depending on what we decide here, has an impact on the conditional
operator. Today the LRM section 8.18 
requires that the datatype of the true and false arms be equivalent. The
LRM defines that 2 class datatypes 
are equivalent if they match, so this seems to imply that you have to
have the same
class datatype. so the following ex is illegal:
 
b1 = (cond ? b :c); // Note that either assigment of b or c to b1 are
legal (not the case if I had c1 = (cond? b:c);
 
but you can write:
b1 = (cond ? b : b1);
 
Can you write
b1 = (cond ? b : null) ; since null does not have a datatype?
 
What happen in the above case if the condition is X? How do we compare
each field of b and null?  They probably do not compare equal so
the assigned value to b1 should be null. 
 
Comments?
 
Francoise
       '
Received on Fri Sep 15 07:25:24 2006

This archive was generated by hypermail 2.1.8 : Fri Sep 15 2006 - 07:25:30 PDT