Previous Up Next

Void

All variables in Cool are initialized to contain values of the appropriate type. The special value \(\rm void\) is a member of all types and is used as the default initialization for variables where no initialization is supplied by the user. (\(\rm void\) is used where one would use \(\rm NULL\) in C or \(\rm null\) in Java; Cool does not have anything equivalent to C's or Java's \(\rm void\) type.) Note that there is no name for \(\rm void\) in Cool; the only way to create a \(\rm void\) value is to declare a variable of some class other than \(\rm Int\), \(\rm String\), or \(\rm Bool\) and allow the default initialization to occur, or to store the result of a \(\rm while\) loop.

There is a special form \(\rm isvoid\ expr\) that tests whether a value is \(\rm void\) (see Section 7.11). In addition, \(\rm void\) values may be tested for equality. A \(\rm void\) value may be passed as an argument, assigned to a variable, or otherwise used in any context where any value is legitimate, except that a dispatch to or case on \(\rm void\) generates a runtime error.

Variables of the basic classes \(\rm Int\), \(\rm Bool\), and \(\rm String\) are initialized specially; see Section 8.

Previous Up Next