Skip to main content

Types declarations Types can be used at four places: Declaring type of global vari- ables. Declaring type of functions. Declaring type of arguments to functions. Declaring type of local variables to functions. Normally, the type information is completely ignored, and can be regarded purely sa documentation. However, when the basic type of a function is declared, then a more strict type checking will be enforced. That means that the type of all arguments must be defined. And, the variables can only be used to store values of the declared type. The function is defined to return an unkown type, as the compiler can't know the type. This value must al- ways be casted (when strict type checking is enabled). Casting a type is done by putting the type name inside a pair of '(' and An example when querying the short description of an object: (string)call_other(ob, "short"); There are two kinds of types. Basic types, and special types. There can be at most one basic type, but any number of special types. The strict type checking is only used by the compiler, not by the runtime. Hence, it is actually possible to store a number in a string variable even when strict type checking is en- abled. Why use strict type checking ? It is really recommended, because the compiler will find many errors at compile time, which will save a lot of hard work. It is in general much harder to trace an error occuring at run time. I recommend, that when a wizard is having problem with an object and wants help, that he first must make all functions have declared types. Basic types An integer 32 bit number. Pointer to an object. An object pointer can mainly be used for two things. Either giving as ar- gument to functions, or used for calling functions defined by that object with its specific instance of variables. An unlimit- ed string of characters. A lot of operators are allowed for strings, like and etc. This type is special, in that it is valid to use in any context. Thus, if everything was declared then the compiler would never complain. This is of course not the idea. It is really only supposed to be used when a variable really is going to contain different types of values. This be avoided if possible. It is good coding practice, to allow a function for example to return different types. This type is only usable for functions. It means that the function will not return any value. The compiler will complain (when type checking is enabled) if the return value is used. Arrays Arrays are declared using a '*' with a basic type. For example, declaring an array of numbers: "int *arr;". Use the type if you want an array of arrays, or a mixed combination of types. Special types There are some special types, which can be given before the basic type. These special types can also be combined. When using spe- cial type before an statement, all symbols defined by inheritance will also get the special type The only special case is symbols, which can not be redefined as in a statement. Can be given for both functions and variables. Functions that are in object can not be called through from another object. And, they are not ac- cessible to any object that inherits This special type behaves different for variables and functions. It is similar to for functions, in that they can not be called from other objects. variables will be neither saved nor restored when calling or A function defined as will always be accessible from other objects, even if is used. All symbols defined as can not be redefined by inheritance. They can still be used and accessed as usual.