Null object: Difference between revisions

Added FreeBASIC
(Added FreeBASIC)
Line 564:
 
In practice, all notable hosted implementations follow the C practice of being able to treat a zero address (i.e. FALSE) as a null address for the purpose of list termination.
 
=={{header|FreeBASIC}}==
<lang freebasic>'FB 1.05.0 Win64
 
' FreeBASIC does not have a NULL keyword but it's possible to create one using a macro
 
#Define NULL CPtr(Any Ptr, 0) '' Any Ptr is implicitly convertible to pointers of other types
 
Type Dog
name As String
age As Integer
End Type
 
Dim d As Dog Ptr = New Dog
d->Name = "Rover"
d->Age = 5
Print d->Name, d->Age
Delete d
d = NULL '' guard against 'd' being used accidentally in future
 
' in practice many FB developers would simply have written: d = 0 above
Sleep</lang>
 
{{out}}
<pre>
Rover 5
</pre>
 
=={{header|Go}}==
Nil is a predefined identifier, defined for six types in Go. In each case, it represents the zero value for the type, that is, the memory representation of all zero bytes. This is the value of a newly created object. In the cases of these six types, an object must be subsequently initialized in some way before it has much use. Examples of initialization are given in the [[Undefined values#Go|Go solution]] of task [[Undefined values]].
9,490

edits