diff --git a/docs/LanguageExtensions.html b/docs/LanguageExtensions.html index 1bccdbd2cc..e9f409ace9 100644 --- a/docs/LanguageExtensions.html +++ b/docs/LanguageExtensions.html @@ -21,6 +21,7 @@ td {
The idea, syntax, and semantics.
+ +Clang provides support for C++ function overloading in C. Function overloading in C is introduced using the overloadable attribute. For example, one might provide several overloaded versions of a tgsin function that invokes the appropriate standard function computing the sine of a value with float, double, or long double precision:
+ +++ ++#include <math.h> +float __attribute__((overloadable)) tgsin(float x) { return sinf(x); } +double __attribute__((overloadable)) tgsin(double x) { return sin(x); } +long double __attribute__((overloadable)) tgsin(long double x) { return sinl(x); } ++
Given these declarations, one can call tgsin with a +float value to receive a float result, with a +double to receive a double result, etc. Function +overloading in C follows the rules of C++ function overloading to pick +the best overload given the call arguments, with a few C-specific +semantics:
+The declaration of overloadable functions is restricted to +function declarations and definitions. Most importantly, if any +function with a given name is given the overloadable +attribute, then all function declarations and definitions with that +name (and in that scope) must have the overloadable +attribute. This rule even applies to redeclarations of functions whose original declaration had the overloadable attribute, e.g.,
+ +++ ++int f(int) __attribute__((overloadable)); +float f(float); // error: declaration of "f" must have the "overloadable" attribute + +int g(int) __attribute__((overloadable)); +int g(int) { } // error: redeclaration of "g" must also have the "overloadable" attribute ++
Functions declared with the overloadable attribute have +their names mangled according to the same rules as C++ function +names. For example, the three tgsin functions in our +motivating example get the mangled names _Z5tgsinf, +_Z5tgsind, and Z5tgsine, respectively. There are two +caveats to this use of name mangling:
+ +Syntax: