inline code - what are MSVC's "rules"
We all know that Visual Studio is trying to support non-Microsoft compilers. I don't know how many are supported but Clang is one of them. Consider this code:-
Code:
#if defined (BUILDING_DLL)
#define DLL_API __declspec(dllexport)
#else
#define DLL_API __declspec(dllimport)
#endif
namespace Gtkmm2ext {
class DLL_API Keyboard
{
public:
Keyboard ();
~Keyboard ();
static Keyboard& get_keyboard() { return *_the_keyboard; }
protected:
static Keyboard* _the_keyboard;
};
} /* namespace */
If the above code appears in a header file, MSVC builds it just fine. But Clang has a habit of inling anything that gets defined in a header file. And of course for anything declared as __declspec(dllimport) that causes huge problems (e.g. functions like get_keyboard() which compile but won't then link...) The Clang devs are willing to fix this but they wanted to know how MSVC handles it (i.e. what the "rules" are). So I asked a question on Microsoft's Developer Community forum. But because Clang isn't a MS compiler, Microsoft just closed the thread!!
So does anyone know how MSVC inlines code? Back in the old days I remember that code would never be inlined if it wasn't declared using inline - and even if it was, inline was only considered as a hint to the compiler. The compiler was free to ignore it. Is that still the case for MSVC or are the rules more complicated these days?
Re: inline code - what are MSVC's "rules"
Re: inline code - what are MSVC's "rules"
Thanks 2kaud - the 3rd link leads to a page with 2 x examples. And the 2nd example states that any function that's defined within a header file is now regarded as being implicitly inlined. But what I can't find out is whether that also apples to DLL functions. My experience suggests that it doesn't - but I just can't find it in writing anywhere... :cry: