OpenCores
URL https://opencores.org/ocsvn/scarts/scarts/trunk

Subversion Repositories scarts

[/] [scarts/] [trunk/] [toolchain/] [scarts-gcc/] [gcc-4.1.1/] [gcc/] [testsuite/] [objc.dg/] [defs.m] - Blame information for rev 20

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 12 jlechner
/* Check if the @defs() construct preserves the correct
2
   offsets of ivars.  */
3
/* Contributed by Ziemowit Laski <zlaski@apple.com>.  */
4
/* { dg-options "-lobjc" } */
5
/* { dg-do run } */
6
 
7
#include <objc/objc.h>
8
#include <objc/Object.h>
9
 
10
extern void abort(void);
11
 
12
#define CHECK_IF(expr) if(!(expr)) abort();
13
 
14
@interface Base: Object {
15
@public
16
  int a;
17
  float b;
18
  char c;
19
}
20
@end
21
 
22
@interface Derived: Base {
23
@public
24
  double d;
25
  unsigned e;
26
  id f;
27
}
28
- init;
29
@end
30
 
31
struct Derived_defs {
32
  @defs(Derived);
33
};
34
 
35
@implementation Base
36
@end
37
@implementation Derived
38
- init {
39
  [super init];
40
  a = 123;
41
  b = 1.23;
42
  c = 'c';
43
  d = 123.456;
44
  e = 456;
45
  f = isa;
46
  return self;
47
}
48
@end
49
 
50
int main(void) {
51
  Derived *derived = [[Derived alloc] init];
52
  struct Derived_defs *derived_defs = (struct Derived_defs *)derived;
53
 
54
  CHECK_IF(derived->a == derived_defs->a && derived_defs->a == 123);
55
  CHECK_IF(derived->b == derived_defs->b && derived_defs->b == (float)1.23);
56
  CHECK_IF(derived->c == derived_defs->c && derived_defs->c == 'c');
57
  CHECK_IF(derived->d == derived_defs->d && derived_defs->d == (double)123.456);
58
  CHECK_IF(derived->e == derived_defs->e && derived_defs->e == 456);
59
  CHECK_IF(derived->f == derived_defs->f && derived_defs->f == derived_defs->isa);
60
 
61
  /* Try out the "inline" notation as well.  */
62
  CHECK_IF(((struct { @defs(Derived); } *)derived)->a == 123);
63
  CHECK_IF(((struct { @defs(Derived); } *)derived)->c == 'c');
64
  CHECK_IF(((struct { @defs(Derived); } *)derived)->e == 456);
65
 
66
  return 0;
67
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.