2007-03-01 Paul Brook <paul@codesourcery.com>
[official-gcc.git] / gcc / testsuite / objc.dg / func-ptr-1.m
blob015d3ac292d61696d5a9648982e8ebd6f08ddc40
1 /* Test for handling of function pointer ivars */
2 /* { dg-do run } */
4 #include <objc/Object.h>
6 extern int strcmp(const char *, const char *);
7 extern void abort(void);
8 #define CHECK_IF(expr) if(!(expr)) abort()
10 typedef float (*floatfunc)(float, float);
12 @interface MyObject : Object
14 @public
15   int (*ivar)(int, int, int);
16   floatfunc ffunc;
18 - init;
19 @end
21 int foo(int a, int b, int c) {
22   return a + b + c;
25 float bar(float a, float b) {
26   return a * b;
29 @implementation MyObject
30 - init {
31   [super init];
32   ivar = foo;
33   ffunc = bar;
34   return self;
36 @end
38 int main ()
40   MyObject *obj = [[MyObject alloc] init];
41   const char *enc = @encode(MyObject);
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);