[cfe-dev] Proposed change to __builtin_overload

Ken Ferry kenferry at gmail.com
Tue Feb 10 15:28:37 PST 2009


On Tue, Feb 10, 2009 at 3:07 PM, Chris Lattner <clattner at apple.com> wrote:

> 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
>

Cool. :-)  Yes, it might be possible to do better than that for the error
anyway, that's just as far as I got.  I don't actually care if this is a
macro either.  The functions Doug suggested would be fine.  Sounds nice.

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


More information about the cfe-dev mailing list