The alias function attribute

The alias function attribute causes the function declaration to appear in the object file as an alias for another symbol. This language feature provides a technique for coping with duplicate or cumbersome names.

Read syntax diagramSkip visual syntax diagramalias function attribute syntax
 
>>-__attribute__------------------------------------------------>
 
>--((--+-alias-----+--(--"original_function_name"--)--))-------><
       '-__alias__-'
 

C The aliased function can be defined after the specification of its alias with this function attribute. C also allows an alias specification in the absence of a definition of the aliased function in the same compilation unit.

C++ The original_function_name must be the mangled name.

The following declares bar to be an alias for __foo:

C only
void __foo(){   /*  function body  */   }
void bar() __attribute__((alias("__foo")));
End of C only
C++ only
extern "C" __foo(){   /*  function body  */   }
void bar() __attribute__((alias("__foo")));
End of C++ only

The compiler does not check for consistency between the declaration of bar and definition of __foo. Such consistency remains the responsibility of the programmer.