2003-12-26 Guilhem Lavaux <guilhem@kaffe.org>
[official-gcc.git] / gcc / testsuite / objc / execute / accessing_ivars.m
blob2c024f5ba7e6b7b087c6be2a62155dcddee3f7f3
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>
6 /* Test that by using -> we can access ivars of other objects of the same 
7    class */
9 @interface TestClass : Object
11   int value;
13 - (int) value;
14 - (int) setValue: (int)number;
15 - (void) takeValueFrom: (TestClass *)object;
16 @end
18 @implementation TestClass : Object
20   int value;
22 - (int) value
23
24   return value;
26 - (int) setValue: (int)number
28   value = number; 
30 - (void) takeValueFrom: (TestClass *)object
32   value = object->value;
34 @end
36 int main (void)
38   TestClass *a;
39   TestClass *b;
41   a = [TestClass new];
42   [a setValue: 10];
43   
44   b = [TestClass new];
45   [b setValue: -10];
47   [b takeValueFrom: a];
49   if ([b value] != [a value])
50     {
51       abort ();
52     }
54   return 0;