0

How should I handle the really simple (should-be-inlined) functions with dlls? If I want it to be inlined, it has to be defined in the header. If I mark it with dllexport, it can't be inline.

Inline case:

  • faster code (simple getters and setters)
  • require recompiling when modifying the implementation
  • implementation has to be in the header
  • can't "hide" the implementation

Export case:

  • possibly slower code because of the stack push/pop and call cost
  • recompile just the specific object
  • implementation is "hidden"

However, what's about with the templates? Specific functions are generated at compile-time from the template functions, so its implementation cannot be in the cpp file. So how should I handle them?

Thanks

Edit

This question was marked as possible duplicate. Well, I don't agree with it. That question is talking about why the template functions have to be defined in the header files (I already know that, read the last section of my original post). My question is talking about the inline/dllexport relationship. Keep in mind that (at least I think) I know how inlining and dllexporting works so it's not another "why can't I export inline functions" question.

csisy
  • 471
  • 3
  • 15
  • Side note: I've read some articles and posts about cost of function calls and inline functions but this is a big topic and none of them provides me a summary about my question. – csisy Jul 23 '15 at 15:32
  • 1
    You cannot have template implementations anywhere else than the headers. C++98 had an `export` keyword that was *intended* to provide this capability, but it was never implemented by the mainstream compilers, and has been removed from C++11. [Related question](http://stackoverflow.com/questions/495021) which has a (partial) workaround in the accepted answer. – DevSolar Jul 23 '15 at 15:32
  • @DevSolar Thanks. I tought about something similar for templates, just wasn't sure this is the best way. :) – csisy Jul 23 '15 at 15:47

0 Answers0