[cfe-commits] r64336 - in /cfe/trunk: include/clang/AST/Attr.h

Howard Hinnant hhinnant at apple.com
Thu Feb 12 08:18:13 PST 2009


On Feb 12, 2009, at 11:10 AM, Douglas Gregor wrote:

>
> On Feb 12, 2009, at 8:02 AM, Douglas Gregor wrote:
>> With macros, of course! :)
>>
>> float __tg_sin(float f) __attribute__((always_inline, overloadable))
>> { return sinf(f); }
>> double __tg_sin(double d) __attribute__((always_inline,  
>> overloadable))
>> { return sin(d); }
>> long double __tg_sin(long double ld) __attribute__((always_inline,
>> overloadable)) { return sin(ld); }
>> #define sin(x) __tg_sin(s)
>
> Sorry, I got my attribute syntax mangled. That should be:
>
> float __attribute__((always_inline, overloadable)) __tg_sin(float f)
> { return sinf(f); }
> double __attribute__((always_inline, overloadable)) __tg_sin(double d)
> { return sin(d); }
> long double __attribute__((always_inline, overloadable)) __tg_sin(long
> double ld) { return sin(ld); }
> #define sin(x) __tg_sin(s)

This sure illustrates how convenient (and concise) it is to have the  
overloadable attribute on the definition.

On Feb 11, 2009, at 6:02 PM, Douglas Gregor wrote:

> This commit adds a new attribute, "overloadable", that enables C++
> function overloading in C. The attribute can only be added to function
> declarations, e.g.,
>
>  int *f(int) __attribute__((overloadable));

Is it practical to lift the "declaration-only" restriction?  Perhaps a  
"first mention of function" rule?

-Howard




More information about the cfe-commits mailing list