#pragma weak (OS/2, Windows)

The #pragma weak directive adds an alternate function name with weak binding for the function function_name.

>>--#--pragma--weak--(--function_name--,--backup_function_name--)--><

If the definition for the function function_name is not found, the linker resolves the function call to the definition for the function backup_function_name. Otherwise, the linker resolves the function call to the definition for function_name.

If function_name is not referenced, neither function_name nor backup_function_name needs to be declared.

If function_name is referenced, both function_name and backup_function_name must be declared.

Note: Both functions must have full prototypes within the compilation unit. Neither function can be a C++ member function.

In the following example , after the program is linked, the call to specialization resolves to the definition of generalization because no definition of specialization exists.

#include <stdio.h>
int generalization(int i) {
  printf("in generalization\n");
}
#pragma weak (specialization, generalization)

int main() {
  printf("in main\n");
  return specialization(6);
}