Next: , Previous: , Up: C   [Index]


Control structures

Control Structures

Generally, Ctalk objects work the same as C variables when they appear in if, for, while, switch, and do-while statements.

If Ctalk cannot figure out a way to resolve an expression that contains both C variables or functions and objects, it will try to warn you.

One exception to these rules are the methods that perform logical negation operator, which generally overload the ‘!’ math operator. When you place a ‘!’ operator at the beginning of a conditional, Ctalk checks whether the class of the expression’s result overloads the operator. In that case, Ctalk treats ‘!’ as a method. If a class does not overload the operator, then Ctalk treats it as a C operator.

That way, you can overload ‘!’ in classes that define complex objects, which provides a flexible way to determine if an object has been initialized or contains valid data.

For example, in X11Font class, you can overload the ‘!’ operator to check whether or not an object’s fontId instance variable is zero to determine whether or not the object refers to a valid font.

If a class doesn’t overload ‘!’, then Ctalk uses the C semantics for the operator - that is, it simply checks whether an operand is zero (or NULL) or non-zero, and inverts the logical true or false value of the operand.

In addition, Ctalk provides many methods to iterate over collections of objects. These methods include map, mapInstanceVariables, mapClassVariables, and overloaded math operators like those in Key class.

For a complete description of the control structures Ctalk uses, refer to the Ctalk Tutorial.


Next: , Previous: , Up: C   [Index]