c3c
c3c copied to clipboard
API stability support
API stability – dynamic libraries (esp OS ones) being able to be both backwards and forwards compatible is an important consideration.
Some things that potentially break the API:
- Function signature changes and availability
- Changes to struct/union size or alignment
- Struct/union internal member ordering and availability
- Enum values
Note that C3 is stable under error changes.
Mitigating 1:
- Multiple functions for the same function
- Hiding function availability behind macros
- ObjC style dynamic dispatch
- ObjC style runtime availability requests
Mitigating 2:
- Structs only available by pointer
Mitigating 3:
- Structs only available by pointer
- Opaque pointer
- "accessor" style access of members
Mitigating 4:
- Enum aliases (e.g. FOO = 3, BAR = FOO)
- Each enum directly defined rather than implicitly
- Using constants rather than enums
Feature:
fn void foo() @dynamic;
Can be checked if it is available, and called if it is:
fn void test()
{
if (foo.available) foo();
}
Roughly this is what it could have been in C:
extern int fooNewFunction(void) __attribute__((dynamic));
int test()
{
if (!__exists(fooNewFunction)) return -1;
fooNewFunction();
}
Under the covers this is added to the client code:
int fooNewFunction(void) { panic(); } __attribute__((noinline) __attribute__((weak));
bool __fooNewFunctionExists __attribute__((weak)) = false ;
Implemented dynamic calls.