Skip to content

[Rcpp-devel] multiple definition problem

1 message · Steve Jaffe

#
I'd be interested in studying those examples if you could provide them.

What I'm describing refers to C++.  The meaning of 'inline' in C is both 
different and more complex -- for one thing it differs between the C99 
and C89 standards. What I recommended would not necessarily prevent 
multiple-definition errors if using a C compiler (but then neither 
would using templates be an option -- therefore I am assuming that this 
discussion is only about C++)

In order to see why it makes sense for C++ to work this way, consider class member
functions defined inside the class declaration. These are inline by default, 
and that is why they do not produce multiple-definition errors although 
they are defined in every compilation unit which includes the class declaration 
header file.

The existence of 'header-only' libraries in C++ (but not C) is another example. True, 
most of these use templates (which also are inline by default -- note that 'inline'
in the C++ sense serves two related but different purposes -- to 'hint' to the compiler
that the code should be inlined, and to *require* the linker to merge multiple definitions.)
But the 'inline'-ness of template functions is what makes this work, and one can
have a header-only C++ library that uses inline functions without templates.

Regards,
Steve

steve_jaffe at yahoo.com