int printf(const char *, ...);
@interface Root
-(id) alloc;
-(id) init;
@end
typedef struct {
float x, y, z[2];
} S;
@interface A : Root {
int myX;
S myZ;
}
@property int x;
@property S z;
@end
@implementation A
-(int) x {
printf("-[A x] = %d\n", myX);
return myX;
}
-(void) setX: (int) arg {
myX = arg;
printf("-[A setX: %d]\n", myX);
}
#if 0#endif
-(S) z {
printf("-[A z] = { %f, %f, { %f, %f } }\n",
myZ.x, myZ.y, myZ.z[0], myZ.z[1]);
return myZ;
}
-(void) setZ: (S) arg {
myZ = arg;
printf("-[A setZ: { %f, %f, { %f, %f } } ]\n",
myZ.x, myZ.y, myZ.z[0], myZ.z[1]);
}
@end
int main(void) {
#define SWAP(T,a,b) { T a_tmp = a; a = b; b = a_tmp; }
A *a = [[A alloc] init];
A *b = [[A alloc] init];
int a0 = 23;
S a2 = { 246, 458, {275, 12} };
int b0 = 42673;
S b2 = { 26, 2, {367, 13} };
a.x = a0;
a.z = a2;
a.x += a0;
b.x = b0;
b.z = b2;
int x0 = (b.x = b0);
printf("(b.x = b0): %d\n", x0);
float x2 = (b.z = b2).x;
printf("(b.z = b2).x: %f\n", x2);
SWAP(int, a.x, b.x);
SWAP(S, a.z, b.z);
return 0;
}