title: Good practices for writing C dynamic libraries [DSOs] (binary compatibility + memory management)
body: <p>I have some experience writing C libraries but I've never read any formal documents describing good practices while writing such libraries. My question pertains around mainly 2 topics:</p>
  
  <ol>
  <li>How to maintain binary compatibility? (I've heard of the pImpl idiom, d-pointer)</li>
  <li>How to design interfaces which remain backward compatible?</li>
  </ol>
  
  <p>The main thing about binary compatibility that I can see from my research is that I can make libraries binary compatible by using the pImpl idiom but changing the structure / adding new data members etc can affect it's binary compatibility even while using pImpl. Also, is there a way to add new methods / functions to a library without actually breaking the binary compatibility? I am assuming adding these things would change the size, layout of the library thus breaking compatibility.</p>
  
  <p>Is there a tool to check binary compatibility?</p>
  
  <p>I have already read these articles. Are there any other docs I can peruse?</p>
  
  <p><a href="http://en.wikipedia.org/wiki/Opaque_pointer" rel="noreferrer">http://en.wikipedia.org/wiki/Opaque_pointer</a></p>
  
  <p><a href="http://techbase.kde.org/Policies/Binary_Compatibility_Issues_With_C++" rel="noreferrer">http://techbase.kde.org/Policies/Binary_Compatibility_Issues_With_C++</a></p>
  
  <p>Also, are there articles which describe ownership issues of memory in the context of designing library interfaces. What are the general conventions? Who owns memory, for how long, who is responsible for deallocating memory etc?</p>