summaryrefslogtreecommitdiff
path: root/gcc/testsuite/objc/execute/accessing_ivars.m
blob: e4c9cf4cd42977c121d6a08cedb3bfe48a97eaab (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
/* Contributed by Nicola Pero - Thu Mar  8 16:27:46 CET 2001 */
#include <stdlib.h>
#ifndef __NEXT_RUNTIME__
#include <objc/objc-api.h>
#endif
#include "../../objc-obj-c++-shared/Object1.h"

/* Test that by using -> we can access ivars of other objects of the same 
   class */

@interface TestClass : Object
{
  int value;
}
- (int) value;
- (int) setValue: (int)number;
- (void) takeValueFrom: (TestClass *)object;
@end

@implementation TestClass : Object
{
  int value;
}
- (int) value
{ 
  return value;
}
- (int) setValue: (int)number
{
  value = number; 
}
- (void) takeValueFrom: (TestClass *)object
{
  value = object->value;
}
@end

int main (void)
{
  TestClass *a;
  TestClass *b;

  a = [TestClass new];
  [a setValue: 10];
  
  b = [TestClass new];
  [b setValue: -10];

  [b takeValueFrom: a];

  if ([b value] != [a value])
    {
      abort ();
    }

  return 0;
}
#include "../../objc-obj-c++-shared/Object1-implementation.h"