Joy Online Manual
Additional Operators
Table of Contents |
Introduction | ||
Pointer Operators | ||
Type-Cast Operator | ||
Sizeof Operator |
& - Address-Of Operator |
SYNOPSIS |
&name
&object.property
&object[index]
... |
DESCRIPTION |
Joy allows you to take the address of any variable or property (provided its type is known).
If successful, this operation will result in a Pointer object. For the & operator to work on variables or arguments, they have to be declared! |
NAME |
* - Pointer-Dereference Operator |
SYNOPSIS |
*object
DESCRIPTION |
You can use *object as a shortcut for object[0], like in C. Of course, this operator is most useful for dereferencing pointers, though it will work on any object. |
NAME |
-> - Arrow Operator |
SYNOPSIS |
object->property
DESCRIPTION |
You can use object->property as a shortcut for object[0].property. This operator is most useful for dereferencing pointers to structures or unions, but you can use it on other objects, too. |
Type-Cast Operator
NAME |
(type) - Type cast operator |
SYNOPSIS |
(type) expression
DESCRIPTION |
Joy understands C-style type casts. You can even cast to array, struct, and union types (which C would not allow).
Type casts are potentially dangerous, especially when pointers are involved, so watch out! When casting to id or Class, Joy will perform the cast only if the argument is "known" to be a valid Objective-C id. You can bypass this safety check (if you are really sure of what you are doing!) by writing Id(address). |
EXAMPLES |
(unsigned) -1
(int) 3.14
(int *) null
(void) f()
(NSRect) [[1,2],[3,4]]
Sizeof Operator
NAME |
sizeof - Sizeof operator |
SYNOPSIS |
sizeof (type)
sizeof name
sizeof object.property
sizeof object[index]
DESCRIPTION |
The result of this operation is the argument's aligned size in bytes. For the sizeof operator to work on variables or arguments, they have to be declared! |
EXAMPLE |
js> typedef struct example {
id anObject;
char *aString;
int anInt;
} Example
js> sizeof(Example)
12
Index |