system verilog null as a literal

P

parag

Guest
are nulls only to used in a equality operators for chandles , class
objects

The LRM does not mention whether null literal is a intergal value or
not. If yes, please let me know the section where it is mentioned as
such

i searched in p1800 but could not find any such refrence

I need to know whether giving an error in this conditions

if (i.a == null ) is correct or not
where i is an interface instance, and a is bit inside it
 
On Oct 13, 11:14 am, parag <parag.p...@gmail.com> wrote:
are nulls only to used in a equality operators for chandles , class
objects

The LRM does not mention whether null literal is a intergal value or
not. If yes, please let me know the section where it is mentioned as
such
hi Parag

Yes, you're right, 1800-2005 is not perfectly clear on this.
The upcoming 2009 standard will fix some of these issues.

As you say, "null" is applicable only to pointer-like things:
chandles, variables of class type, and virtual interface variables.
Any such variable can have "null" assigned to it, and
any such variable can be compared to "null":

class C;
...
endclass

C c, c2;
virtual some_interface_name v;
chandle h;

initial begin
c = null; // OK
v = null; // OK
h = null; // OK

if (
(c != null) // OK
&& (v == null) // OK
&& (h == null) // OK
) ....;

c2 = (condition) ? c : null; // OK


I need to know whether giving an error in this conditions
if (i.a == null ) is correct or not
where i is an interface instance, and a is bit inside it
Do you really mean "bit"? You cannot compare "null" with
an integral value such as a bit. On the other hand, if i.a
is a chandle, class-type variable or virtual interface then
your test is OK.

Note also that most simulators support this:

C c; // variable of some class type
initial begin
if (c) ... // OK, same as "if (c != null)"

Hope this helps
--
Jonathan Bromley
 
On Oct 14, 2:36 pm, Jonathan Bromley <s...@oxfordbromley.plus.com>
wrote:
On Oct 13, 11:14 am, parag <parag.p...@gmail.com> wrote:

are nulls only to used in a equality operators for chandles , class
objects

The LRM does not mention whether null literal is a intergal value or
not. If yes, please let me know the section where it is mentioned as
such

hi Parag

Yes, you're right, 1800-2005 is not perfectly clear on this.
The upcoming 2009 standard will fix some of these issues.

As you say, "null" is applicable only to pointer-like things:
chandles, variables of class type, and virtual interface variables.
Any such variable can have "null" assigned to it, and
any such variable can be compared to "null":

  class C;
    ...
  endclass

  C c, c2;
  virtual some_interface_name v;
  chandle h;

  initial begin
    c = null; // OK
    v = null; // OK
    h = null; // OK

    if (
       (c != null)   // OK
    && (v == null)   // OK
    && (h == null)   // OK
    ) ....;

    c2 = (condition) ? c : null; // OK

I need to know whether giving an error in this conditions
if (i.a == null ) is correct or not
where i is an interface instance, and a is bit inside it

Do you really mean "bit"?  You cannot compare "null" with
an integral value such as a bit.  On the other hand, if i.a
is a chandle, class-type variable or virtual interface then
your test is OK.

Note also that most simulators support this:

  C c;  // variable of some class type
  initial begin
    if (c) ...   // OK, same as "if (c != null)"

Hope this helps
--
Jonathan Bromley
Problem is we were supporting this for some testbench in some
propreitary cusotmer design

we basically changed the behavior to allow for such comaprisons for
binary , case , wildcard equality

And we gave the conscious decision upon the user to choose the
correctness ,
he or she may want to use a null literal if he wants with a bit.
( customer came back sayign that LRM does not stop it, )

I tried the draft 8 for p1800-2009 but did not get any such help .
there are examples of null only in teh context of pointer like
variables
as you have mentioned.
 
Parag

we basically changed the behavior to allow for such comaprisons for
binary , case , wildcard equality
Why? I cannot imagine any scenario in which I would want to do that.

And we gave the conscious decision upon the user to choose the
correctness ,
he or she may want to use a null literal if he wants with a bit.
The customer is always right, even when he's wrong!

( customer came back sayign that LRM does not stop it, )
Hmmm. I guess that's true; however, the SV-LRM doesn't stop
murder either, but it's still a bad thing to do :)

I tried the draft 8 for p1800-2009 but did not get any such help .
there are examples of null only in teh context of pointer like
variables as you have mentioned.
(Including event handles, which I forgot to mention before.)

Sure, and that should be enough hint that there is no coercion
from null to any integral value. There was a lot of discussion
concerning the data type of null in SV-EC, and the conclusion
was that null has no data type but can participate in various
expressions in ways that _are_ clearly described in the 2009 LRM.
I thought we had added something to the LRM about this, and
in particular I had a recollection that we added something about
null to the type matching/equivalence rules, but that is not so;
apologies for misleading you.

Note that this has been discussed recently on the sv-ec
reflector where another implementer raised a similar question:
see thread beginning http://www.eda.org/sv-ec/hm/7174.html
I guess that if someone from your team had responded to that
thread, it might have looked a little different...

cheers
--
Jonathan Bromley
 

Welcome to EDABoard.com

Sponsor

Back
Top