I’m curious if this would be useful for a case I’ve hit as a user of compilers.
In Cocoa and CoreFoundation, there are a bunch of types that different as far as the compiler is concerned, but the user knows that they are the same. NSString* and CFStringRef are interchangeable, for example.
I’d love to be able to inform the compiler that certain types are compatible, but short of that, I have an NSToCF macro that does sort of a type-safe cast. If passed an argument of type of NSString*, for example, the result is type CFStringRef. It looks like this:
#define NSToCF(nsObject) (
__builtin_choose_expr (__builtin_types_compatible_p (typeof (nsObject), NSArray*), (CFArrayRef)(nsObject),
__builtin_choose_expr (__builtin_types_compatible_p (typeof (nsObject), NSAttributedString*), (CFAttributedStringRef)(nsObject),
__builtin_choose_expr (__builtin_types_compatible_p (typeof (nsObject), NSCalendar*), (CFCalendarRef)(nsObject),
__builtin_choose_expr (__builtin_types_compatible_p (typeof (nsObject), NSCharacterSet*), (CFCharacterSetRef)(nsObject),
__builtin_choose_expr (__builtin_types_compatible_p (typeof (nsObject), NSData*), (CFDataRef)(nsObject),
__builtin_choose_expr (__builtin_types_compatible_p (typeof (nsObject), NSDate*), (CFDateRef)(nsObject),
__builtin_choose_expr (__builtin_types_compatible_p (typeof (nsObject), NSDictionary*), (CFDictionaryRef)(nsObject),
__builtin_choose_expr (__builtin_types_compatible_p (typeof (nsObject), NSError*), (CFErrorRef)(nsObject),
__builtin_choose_expr (__builtin_types_compatible_p (typeof (nsObject), NSLocale*), (CFLocaleRef)(nsObject),
__builtin_choose_expr (__builtin_types_compatible_p (typeof (nsObject), NSMutableArray*), (CFMutableArrayRef)(nsObject),
__builtin_choose_expr (__builtin_types_compatible_p (typeof (nsObject), NSMutableAttributedString*), (CFMutableAttributedStringRef)(nsObject),
__builtin_choose_expr (__builtin_types_compatible_p (typeof (nsObject), NSMutableCharacterSet*), (CFMutableCharacterSetRef)(nsObject),
__builtin_choose_expr (__builtin_types_compatible_p (typeof (nsObject), NSMutableData*), (CFMutableDataRef)(nsObject),
__builtin_choose_expr (__builtin_types_compatible_p (typeof (nsObject), NSMutableDictionary*), (CFMutableDictionaryRef)(nsObject),
__builtin_choose_expr (__builtin_types_compatible_p (typeof (nsObject), NSMutableSet*), (CFMutableSetRef)(nsObject),
__builtin_choose_expr (__builtin_types_compatible_p (typeof (nsObject), NSMutableString*), (CFMutableStringRef)(nsObject),
__builtin_choose_expr (__builtin_types_compatible_p (typeof (nsObject), NSNumber*), (CFNumberRef)(nsObject),
__builtin_choose_expr (__builtin_types_compatible_p (typeof (nsObject), NSInputStream*), (CFReadStreamRef)(nsObject),
__builtin_choose_expr (__builtin_types_compatible_p (typeof (nsObject), NSTimer*), (CFRunLoopTimerRef)(nsObject),
__builtin_choose_expr (__builtin_types_compatible_p (typeof (nsObject), NSSet*), (CFSetRef)(nsObject),
__builtin_choose_expr (__builtin_types_compatible_p (typeof (nsObject), NSString*), (CFStringRef)(nsObject),
__builtin_choose_expr (__builtin_types_compatible_p (typeof (nsObject), NSTimeZone*), (CFTimeZoneRef)(nsObject),
__builtin_choose_expr (__builtin_types_compatible_p (typeof (nsObject), NSURL*), (CFURLRef)(nsObject),
__builtin_choose_expr (__builtin_types_compatible_p (typeof (nsObject), NSOutputStream*), (CFWriteStreamRef)(nsObject),
1.0/error on type not found/ )))))))))))))))))))))))))
Would the changes you’re talking about make this less disgusting?
-Ken