www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/02/10/16:01:52

From: Martynas Kunigelis <algikun AT santaka DOT sc-uni DOT ktu DOT lt>
Newsgroups: comp.os.msdos.djgpp
Subject: C++ templates: another reason to switch to ELF
Date: Mon, 10 Feb 1997 16:11:30 +0000
Organization: LITNET
Lines: 21
Message-ID: <Pine.HPP.3.95.970210160423.6237C-100000@santaka.sc-uni.ktu.lt>
NNTP-Posting-Host: santaka.sc-uni.ktu.lt
Mime-Version: 1.0
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

Hi folks!

You might or might not be familiar with the problem g++ has with
templates: if you instantiate a particular class/function template with
the same parameters in different translation units, code for those
instances will be duplicated everywhere you do so. There's a workaround
using #pragma interface/implementation, but it's unportable and rather
ugly. Borland solved this problem by adding extra intelligence to their
linker, so the linker eliminates duplicated code. GNU linker also can do
this, but only for two formats: ELF and AOUT. The key here is
__attribute__((weak)), which is supported only on these two formats. In
fact, ELF-configured g++ emits weak attribute for every piece of template
code, so duplicated stuff gets eliminated. Voila! There's also a Cygnus
patch implementing template instance repository a la CFront, but it's
unofficial and has many other disadvantages.

Anyone willing to do the hard job?

Martynas


- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019