Created
February 15, 2013 23:52
-
-
Save boredzo/4964590 to your computer and use it in GitHub Desktop.
Initialization of block pointer variable with incompatible block using wrong syntax passes without error or warning
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #import <Foundation/Foundation.h> | |
| int main(int argc, char *argv[]) { | |
| @autoreleasepool { | |
| /*Note the use of Objective-C method-style return type syntax. | |
| *That's not actually the correct syntax, but the incorrect syntax passes compilation | |
| *without a warning even though these blocks have different and incompatible signatures! | |
| */ | |
| id (^wat)(int x, int y) = (id)^(CGFloat x, CGFloat y) { | |
| return @(hypot(x, y)); | |
| }; | |
| NSLog(@"Expected result: %f", hypot(640, 480)); | |
| NSLog(@"Actual result: %@", wat(640, 480)); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment