Topic: Explicitly instantiating inline functions


Author: Usenet@aristeia.com (Scott Meyers)
Date: Mon, 30 Sep 2002 23:57:21 +0000 (UTC)
Raw View
Suppose I have a template for an inline function and I explicitly
instantiate it:

  template<typename T>
  inline
  void f(T) {}                   // f ignores its argument

  template void f<int>(int);     // explicitly instantiate f<int>

Does the Standard have anything to say about whether I will get a copy of f
in my object file?  My impression is that it does not, and a couple of
simple experiments suggest that different compilers behave differently in
this regard.

Thanks,

Scott

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html                       ]





Author: david.abrahams@rcn.com ("David Abrahams")
Date: Tue, 1 Oct 2002 17:10:44 +0000 (UTC)
Raw View
"Scott Meyers" <Usenet@aristeia.com> wrote in message
news:MPG.180283e5339df4e89896cc@news.hevanet.com...

> Suppose I have a template for an inline function and I explicitly
> instantiate it:
>
>   template<typename T>
>   inline
>   void f(T) {}                   // f ignores its argument
>
>   template void f<int>(int);     // explicitly instantiate f<int>
>
> Does the Standard have anything to say about whether I will get a copy of
f
> in my object file?

No. The standard doesn't even have  a notion of "a copy of f" or "object
file" for that matter. All you know is that whenver you write an expression
that takes the address of the function, you get the same value.

--
-----------------------------------------------------------
           David Abrahams * Boost Consulting
dave@boost-consulting.com * http://www.boost-consulting.com


---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html                       ]