OSDN Git Service

Added.
[pf3gnuchains/gcc-fork.git] / gcc / testsuite / objc / execute / accessing_ivars.m
1 /* Contributed by Nicola Pero - Thu Mar  8 16:27:46 CET 2001 */
2 #include <objc/objc.h>
3 #include <objc/objc-api.h>
4 #include <objc/Object.h>
5
6 /* Test that by using -> we can access ivars of other objects of the same 
7    class */
8
9 @interface TestClass : Object
10 {
11   int value;
12 }
13 - (int) value;
14 - (int) setValue: (int)number;
15 - (void) takeValueFrom: (TestClass *)object;
16 @end
17
18 @implementation TestClass : Object
19 {
20   int value;
21 }
22 - (int) value
23
24   return value;
25 }
26 - (int) setValue: (int)number
27 {
28   value = number; 
29 }
30 - (void) takeValueFrom: (TestClass *)object
31 {
32   value = object->value;
33 }
34 @end
35
36 int main (void)
37 {
38   TestClass *a;
39   TestClass *b;
40
41   a = [TestClass new];
42   [a setValue: 10];
43   
44   b = [TestClass new];
45   [b setValue: -10];
46
47   [b takeValueFrom: a];
48
49   if ([b value] != [a value])
50     {
51       abort ();
52     }
53
54   return 0;
55 }