typedef (void (^blockType)());
I need blocks with different types of arguments in the same type blockTypeand call it as the original type later. But there is a problem when creating a lock type.
The following code works well with any type of argument, ...
((blockType)^(BOOL b) {
NSLog(@"BOOL: %d", b);
})(YES);
((blockType)^(int i) {
NSLog(@"int: %d", i);
})(1);
((blockType)^(double f) {
NSLog(@"double: %f", f);
})(1.0 / 3);
((blockType)^(NSString *s) {
NSLog(@"NSString *: %@", @"string");
})(1.0 / 3);
except float :
((blockType)^(float f) {
NSLog(@"float: %f", f);
})(1.0f);
((blockType)^(float f) {
NSLog(@"float: %f", f);
})(1.0f / 3);
but this is fine without casting:
(^(float f) {
NSLog(@"float without casting: %f", f);
})(1.0 / 3);
How to explain and solve the problem?
source
share