OSDN Git Service

2005-12-11 Andrew Pinski <pinskia@physics.uc.edu>
[pf3gnuchains/gcc-fork.git] / gcc / testsuite / objc.dg / func-ptr-1.m
1 /* Test for handling of function pointer ivars */
2 /* { dg-do run } */
3
4 #include <objc/Object.h>
5
6 extern int strcmp(const char *, const char *);
7 extern void abort(void);
8 #define CHECK_IF(expr) if(!(expr)) abort()
9
10 typedef float (*floatfunc)(float, float);
11
12 @interface MyObject : Object
13 {
14 @public
15   int (*ivar)(int, int, int);
16   floatfunc ffunc;
17 }
18 - init;
19 @end
20
21 int foo(int a, int b, int c) {
22   return a + b + c;
23 }
24
25 float bar(float a, float b) {
26   return a * b;
27 }
28
29 @implementation MyObject
30 - init {
31   [super init];
32   ivar = foo;
33   ffunc = bar;
34   return self;
35 }
36 @end
37
38 int main ()
39 {
40   MyObject *obj = [[MyObject alloc] init];
41   const char *enc = @encode(MyObject);
42
43   CHECK_IF(obj->ivar(4, 5, 6) == 15);
44   CHECK_IF(obj->ffunc(34.0, 45.0) == 34.0 * 45.0);
45   CHECK_IF(!strcmp(enc, "{MyObject=#^?^?}"));
46   return(0);
47 }
48