Search code examples
cshared-librariesbackwards-compatibilityc11

Are C Shared Object Backwards Compatible (Standard-Wise)


I have a rather simple question:

I want to write a library (to be used in other projects via a .so file) which uses the C11-Specific _Generic keyword. I would love it if projects using the library did not need to compile their project using the C11 standard. Is this possible?

PS: I Googled a bit and didn't see an answer, and I'm on my phone, so, as a forewarning, there's no "Possible Duplicates" list on my screen.


Solution

  • The .so file will know nothing about _Generic, the decisions that this feature makes are at compile time.

    What you should worry about are your header files. If you'd have "stray" _Generic in there and a client has a pre-C11 compiler, this would crash. So you'd have to #if/#else the part of your headers with __STDC_VERSION__ to protect pre-C11 compilers to see this.