- To: Timothy Madden <terminatorul@xxxxxxxxx>
- Subject: Re: One-definition rule for inline functions
- From: Jonathan Wakely <jwakely.gcc@xxxxxxxxx>
- Date: Thu, 8 Mar 2012 09:24:42 +0000
- Cc: gcc-help@xxxxxxxxxxx
- Comment: DKIM? See http://www.dkim.org
- Comment: DomainKeys? See http://antispam.yahoo.com/domainkeys
- Dkim-signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=gcc.gnu.org; s=default; x=1331803507; h=Comment: DomainKey-Signature:Received:Received:Received:Received: MIME-Version:Received:Received:In-Reply-To:References:Date: Message-ID:Subject:From:To:Cc:Content-Type:Mailing-List: Precedence:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:Sender:Delivered-To; bh=EaXgh9Z6v9xfudb6T49fBCuIhHU=; b=N5FnpvlN0TVq0vLArBMgTHLHoiKxl2q8FaiUUSfxfKVgdf7vL+ggwWP0a1E2Gq jg7ucl5JO6TNGt97zyDsR/vmpPvTvCNzop6xUfjy2uodUi+HOukyeCNeFt9p4aY+ mhpqjx9Q/LO4HY7hsfJmIJW4dePC+2OJFjEdPt8vpokc0=
- In-reply-to: <jj92u0$kl2$1@dough.gmane.org>
On 8 March 2012 01:44, Timothy Madden wrote:
>
> What does g++ do with this template ?
> Does it really compile any templates in each and every .cc file that they
> are used in ?
Yes, as it says at the same page
(http://gcc.gnu.org/onlinedocs/gcc/Vague-Linkage.html) templates also
have vague linkage. If you follow the "Where's the template?" link
there's a whole page on the topic:
http://gcc.gnu.org/onlinedocs/gcc/Template-Instantiation.html (ignore
the paragraph about "a future version of G++")
You can use an explicit instantiation declaration (i.e. "extern
template") to suppress the implicit instantiation in every file that
uses the template:
extern template void draw_unit_vector<int>();
If you do that then you must ensure that an explicit instantiation
definition appears in exactly one object file:
template void draw_unit_vector<int>();
[Linux C Programming]
[Linux Kernel]
[eCos]
[Fedora Development]
[Fedora Announce]
[Autoconf]
[The DWARVES Debugging Tools]
[Yosemite Campsites]
[Yosemite News]
[Linux GCC]