C API Pattern for Binary Compatibility

This is pattern I observe often in operating system APIs.

This is a problem - say you have a standard which changes. Like IP4 versus IP6 internet addresses.

How as an API designer for an operating system can I make it so my API can support the new extended format but not break existing older applications which aren’t aware of the new extended format?

Well a common way to solve this problem is to use a struct under the hood and then:

  • Code the type of the struct using an short integer at the start of the struct to identify it’s version or type

  • Also give its length.

Â