[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
a question using performv
From: |
]d |
Subject: |
a question using performv |
Date: |
Tue, 26 Feb 2002 00:18:43 +0700 |
User-agent: |
Mozilla/5.0 (X11; U; Linux i686; en-US; rv:0.9.8) Gecko/20020211 |
this is my problem source
#import <objc/Object.h>
@interface Myclass:Object {
id target;
int iden;
}
- setTarget:(id) nt;
- setIden:(int) ni;
- printnumber:(int)i1 :(int)i2;
@end
@implementation Myclass
- setTarget:(id) nt {
target = nt;
return self;
}
- setIden:(int) ni {
iden = ni;
return self;
}
- printnumber:(int)i1 :(int)i2 {
printf("%d - %d %d\n",iden, i1, i2);
if (target) {
printf("call target\n");
[target performv:_cmd :__builtin_apply_args()];
printf("end target\n");
}
printf("%d - %d %d\n",iden, i1, i2);
return self;
}
@end
int main() {
id x1;
id x2;
x1 = [[[Myclass alloc] init]setIden:1];
x2 = [[[Myclass alloc] init]setIden:2];
[x1 setTarget:x2];
[x1 printnumber:123 :456];
}
gcc -O2 test.m -lobjc -lpthread
will produce
1 - 123 456
call target
2 - 123 456
2 - 123 456
end target
1 - 123 456
and gcc test.m -lobjc -lpthread
will produce
1 - 123 456
call target
2 - 123 456
2 - 123 456
end target
2 - 123 456
outputs
I am wondering if the usage of
target performv:_cmd :__builtin_apply_args()];
is correct.
http://developer.apple.com/techpubs/macosx/DeveloperTools/Compiler/Compiler.22.html
make it sound safe to use it the way I did.
I just wish there's a simple way to do this. a portable way.
best regards,
]d