Re: inline abuse in ATL ?
MrAsm <firstname.lastname@example.org> wrote:
Reading ATL samples and headers, it seems to me that there is a modus
operandi consisting of defining methods and functions to be "inline",
even if they are long.
I thought that C++ "inline" keyword should be used only for very short
functions, like simple accessors:
But if we look at e.g. "atlenc.h" file there are some big functions
like "Base64Encode" or "Base64Decode" that are defined inline.
So, what's your opinion about that?
ATL mostly consists of templates. Templates have to be implemented in
Since the bulk of ATL code has to be in header files anyway, ATL
developers didn't want to bother shipping a static library, and forcing
you to configure your project to link to it, for the small number of
non-template functions and classes present in ATL. They declare a
function in the header with "inline" keyword, and you can just include
the header and let the compiler and linker do the rest.
Note that "inline" keyword is just a hint to the compiler: the compiler
will not inline a function it believes not to be small enough to benefit
from inlining (and vice versa, the compiler may choose to inline a small
function not explicitly marked inline). But "inline" keyword changes the
behavior of the linker. Normally, if linker sees two definitions of the
same function in two .obj files, it will complain. But if these
functions are marked inline, the linker will quietly choose one
definition and throw away any others.
With best wishes,
With sufficient thrust, pigs fly just fine. However, this is not
necessarily a good idea. It is hard to be sure where they are going to
land, and it could be dangerous sitting under them as they fly
overhead. -- RFC 1925