Null object: Difference between revisions

Content added Content deleted
(Move BASIC and part of ActionScript to Undefined values.)
Line 9: Line 9:
trace("object is null");</lang>
trace("object is null");</lang>


ActionScript also has a special '''undefined''' value which applies to untyped variables and properties of dynamic classes which have not been initialized.
ActionScript also has an '''undefined''' value: see [[Undefined values#ActionScript]].
<lang actionscript>var foo; // untyped
var bar:*; // explicitly untyped

trace(foo + ", " + bar); // outputs "undefined, undefined"

if (foo == undefined)
trace("foo is undefined"); // outputs "foo is undefined"</lang>


=={{header|Ada}}==
=={{header|Ada}}==
Line 24: Line 17:
Ada.Text_Io.Put_line("object is null");
Ada.Text_Io.Put_line("object is null");
end if;</lang>
end if;</lang>

=={{header|ALGOL 68}}==
=={{header|ALGOL 68}}==
In ALGOL 68 the NIL yields a name that does not refer to any value. NIL can never be
In ALGOL 68 the NIL yields a name that does not refer to any value. NIL can never be
Line 89: Line 83:
display dialog "x is null"
display dialog "x is null"
end if</lang>
end if</lang>

=={{header|AutoHotkey}}==
=={{header|AutoHotkey}}==
<lang AutoHotkey>If (object == null)
<lang AutoHotkey>If (object == null)
MsgBox, object is null</lang>
MsgBox, object is null</lang>


=={{header|BASIC}}==
Classic BASIC does have the concept of un-initialised or undefined variables.
=={{header|C}}==
=={{header|C}}==
C has the null pointer, written as "0", whose internal representation is often, [http://c-faq.com/null/varieties.html though not always], the same as integer zero. It is (supposedly) garanteed to be pointing to nothing, so receiving one of those likely means you are not looking at an object--<i>but</i>, there are occasions where changing content of a null pointer actually does something (say, on DOS); and a function that's supposed to return a pointer on success doesn't always return a 0 otherwise (e.g. mmap returns -1 for failure).
C has the null pointer, written as "0", whose internal representation is often, [http://c-faq.com/null/varieties.html though not always], the same as integer zero. It is (supposedly) garanteed to be pointing to nothing, so receiving one of those likely means you are not looking at an object--<i>but</i>, there are occasions where changing content of a null pointer actually does something (say, on DOS); and a function that's supposed to return a pointer on success doesn't always return a 0 otherwise (e.g. mmap returns -1 for failure).