title: Inline and dlimport/dllexport
body: <p>Now I analyse some old code, which was not written by me. In headers there are many declarations like this:</p>
  
  <pre><code>SVPDSDKDLLEXPORT inline C3vec mult(C3vec src, D3DXMATRIX &amp;m);
  </code></pre>
  
  <p>SVPDSDKDLLEXPORT is defined as _declspec(dllexport), if it is used in SVPDSDK; as _declspec(dllimport), if it is used in any project, which uses SVPDSDK.dll. Inlining here seems very strange for me as there is no definition in the header, it is in .cpp file, but compilation and linkage of SVPDSDK and all projects, which use respective DLL, are executed without any problems. I assume, that it is just ignored and the function is exported as though is was not inlined. </p>
  
  <p>I've found this discussion:
  <a href="https://stackoverflow.com/questions/8876279/c-inline-functions-with-dllimport-dllexport">C++ : inline functions with dllimport/dllexport?</a></p>
  
  <p>Looked like I should have removed "inline" from all such declarations, don't mix inlining and export/import. But then I found this topic in MSDN:
  <a href="http://msdn.microsoft.com/en-us/library/xa0d9ste" rel="nofollow noreferrer">http://msdn.microsoft.com/en-us/library/xa0d9ste</a></p>
  
  <p>I don't understand some parts of it. </p>
  
  <blockquote>
    <p>You can define as inline a function with the dllexport attribute. In this case, the function is always   instantiated and exported, whether or not any module in the program references the function. The function   is presumed to be imported by another program. </p>
  </blockquote>
  
  <p>Firstly, "the function is always instantiated", what does it mean? I've found only topics about template functions instantiation in C++, no any other instantiation. Is it connected only with templates or not? </p>
  
  <p>Secondly, "the function is always exported". I don't understand it at all. Is it possible, that function with declspec(_dllexport) is not exported in some cases? In what cases?</p>
  
  <p>Now about import:</p>
  
  <blockquote>
    <p>You can also define as inline a function declared with the dllimport attribute. In this case, the function can be expanded (subject to /Ob specifications), but never instantiated. In particular, if the address of an inline imported function is taken, the address of the function residing in the DLL is returned. This behavior is the same as taking the address of a non-inline imported function.</p>
  </blockquote>
  
  <p>Again, I don't understand, what means instantiation in this case. </p>
  
  <p>While writing this question and analysing topic from MSDN, I made a conclusion, that function, which is exported/imported and inlined at the same time, is inlined only in its project itself (SVPDSDK in my case) and is non-inlined in all importing projects. It's not evidently declared in MSDN topic. If I don't import it in any project, which uses it, and I have not a definition in its header file, it will be an ordinary inlined function, so I will get a linkage error. Then it seems for me that it's agreeable to mix inlining and export/import, thought it contradicts an answer in the stackoverflow discussion, mentioned above. Am I right?<br>
  And I still don't understand all this words about inlined functions instantiation.</p>
  
  <p>I'm sorry, that I combined some questions in one topic, but I don't know, how to divide it in separate ones, because they are united by the same issue and the same materials. However, I would be grateful, if anyone could clarify this questions for me.   </p>