[cfe-dev] Proposed change to __builtin_overload

Chris Lattner clattner at apple.com
Tue Feb 10 15:07:37 PST 2009


On Feb 10, 2009, at 2:57 PM, Douglas Gregor wrote:
>> (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?
>
>
> I believe so. The idea would be to create a bunch of overloaded  
> functions like so:
>
>   inline CFArrayRef NSToCF(NSArray *nsObject)  
> __attribute__((always_inline, overloaded)) { return  
> (CFArrayRef)nsObject; }
>   inline CFAttributedStringRef NSToCF(NSAttributedString *nsObject)  
> __attribute__((always_inline, overloaded)) { return  
> (CFAttributedStringRef)nsObject; }
>   inline CFCalendarRef NSToCF(NSCalendar *nsObject)  
> __attribute__((always_inline, overloaded)) { return  
> (CFCalendarRef)nsObject; }
>   inline CFDataRef NSToCF(NSData *nsObject)  
> __attribute__((always_inline, overloaded)) { return  
> (CFDataRef)nsObject; }
>   // and so on
>
> It's better than counting parentheses :)

right, it is easy to turn that into a macro.  :)  It is also a lot  
better in the error case than "1.0/*error on type not found*/ " :)

-Chris
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20090210/8b1ba53a/attachment.html>


More information about the cfe-dev mailing list