[cfe-dev] RFC: Function Overloading in C

Fariborz Jahanian fjahanian at apple.com
Fri Feb 13 09:01:06 PST 2009


On Feb 13, 2009, at 8:39 AM, Douglas Gregor wrote:

>
> On Feb 13, 2009, at 2:01 AM, Sebastian Redl wrote:
>
>> Douglas Gregor wrote:
>>> Hi all,
>>>
>>> I've just finished the implementation of the "overloadable" function
>>> attribute that introduces function overloading into C. The intent is
>>> to make it easier to implement "type-generic" functions (such as
>>> those
>>> in tgmath.h and altivec.h). The feature is in Clang's trunk, and is
>>> documented here:
>>>
>>> 	http://clang.llvm.org/docs/LanguageExtensions.html#overloading-in-c
>>>
>>> Comments welcome!
>>>
>> I wonder if it's possible (and a good idea) to use the C++ linkage
>> specification syntax for this, i.e.
>>
>> extern "C++" double tgsin(double d) { return sin(d); }
>> extern "C++" float tgsin(float f) { return sinf(f); }
>> extern "C++" long double tgsin(long double d) { return sinl(d); }
>>
>> As a C++ programmer, it looks more natural to me.
>
> Huh. I never even thought of that!
>
>> Of course, I have no
>> idea how this would look to a pure C programmer. Also, this syntax
>> would
>> imply that we will always mangle this like C++ names.
>
>
> I'm on the fence with this one. My main concern is that 'extern "C++"'
> is very open-ended, and users seeing this in code might be tempted to
> try all sorts of crazy C++ things following the 'extern "C++"'. We'll
> need to make sure we reject all those, otherwise they might work and
> users might start relying on them :)
>
> I like the "overloadable" attribute better in this regard, because it
> is (was) easy to lock it down and make it only work in very specific
> circumstances. Plus, it gives us a lot of wiggle room w.r.t. the
> mangling of these names.

It looks weird to apply extern "C++' on an overloadable 'static'  
function.

- Fariborz

>
>
> 	- Doug
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev




More information about the cfe-dev mailing list