Enabling Users to Override Functions in C & C++

8 May 2020 by Phillip Johnston • Last updated 14 December 2021There are many cases were we want to give our users the ability to override functions in a library or module. This is often for be for customization or optimization purposes. The Pattern With many C and C++ compilers, we can declare function and variable definitions as “weakly linked” using __attribute__((weak)) or the __weak alias: __attribute__((weak)) void weak_function() { // Intentional no-op } Note: While ELF allows you to declare a symbol with weak linkage and not supply a definition, this approach will fail with Mach-O objects and OS

To access this content, you must purchase a Membership - check out the different options here. If you're a member, log in.