www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1995/07/16/04:16:08

Original-Received: by ulysses.lib.ntua.gr via
NTUAnet with ESMTP id KAA01374 at Sun, 16 Jul 1995 10:32:09
+0300
PP-warning: Illegal Received field on preceding line
Original-Received: by cc.ece.ntua.gr with ESMTP id KAA03644 at Sun, 16
Jul 1995 10:35:44 +0300
PP-warning: Illegal Received field on preceding line
From: "George C. Moschovitis" <gmoscho AT cc DOT ece DOT ntua DOT gr>
Subject: more template problems...
To: djgpp AT sun DOT soe DOT clarkson DOT edu (djgpp)
Date: Sun, 16 Jul 1995 10:33:19 +0300 (EET DST)

Hi,


	I have the following problem with template instantiation. Here comes
	a little program that generates the problem :


------------------------------------------------- file  t.h  -----------------

#pragma interface

//**************************************************************************//
template <class T>
class	tpl1 {
public:
 T     	       *p1;
 T		a[10];

public:
  		tpl1();
	       ~tpl1();

inline void	function1();
};

template <class T>
tpl1<T>::tpl1()
{
  p1 = new T;
}

template <class T>
tpl1<T>::~tpl1()
{
  delete p1;
}

template <class T>
inline void	tpl1<T>::function1()
{
  p1++;
}


//**************************************************************************//
template <class T>
class	tpl2 {
public:
 T	*p1;
 T	*p2;
};


//**************************************************************************//
class	ftpl1 {
public:
 tpl1<int>	a;
 tpl1<char>	b;
 tpl1<float>    c;
};


//**************************************************************************//
typedef	tpl2<int>	ftpl2;


//**************************************************************************//
typedef tpl2<ftpl2>	ftpl3;


-------------------------------------------------- file t.cc -----------------

#include "t.h"

main()
{
  int a = 3;
}




	i compile the above programm with:
	
gcc -S -fexternal-templates -fno-implement-inlines -m486 -O3 t.cc
	
	using gcc 2.6.3 which comes with the djgpp (V2beta1) package and i get
	the following output:
	
	
	.file	"t.cc"
gcc2_compiled.:
___gnu_compiled_cplusplus:
.text
	.align 4
.globl _function1__t4tpl11Zi
_function1__t4tpl11Zi:
	pushl %ebp
	movl %esp,%ebp
	movl 8(%ebp),%eax
	addl $4,(%eax)
	movl %ebp,%esp
	popl %ebp
	ret
	.align 4
.globl _function1__t4tpl11Zc
_function1__t4tpl11Zc:
	pushl %ebp
	movl %esp,%ebp
	movl 8(%ebp),%eax
	incl (%eax)
	movl %ebp,%esp
	popl %ebp
	ret
	.align 4
.globl _function1__t4tpl11Zf
_function1__t4tpl11Zf:
	pushl %ebp
	movl %esp,%ebp
	movl 8(%ebp),%eax
	addl $4,(%eax)
	movl %ebp,%esp
	popl %ebp
	ret
	.align 4
.globl _main
_main:
	pushl %ebp
	movl %esp,%ebp
	call ___main
	xorl %eax,%eax
	movl %ebp,%esp
	popl %ebp
	ret
	
	
	
	as u see there is code emmited for the 2 inline functions !!
	this code not only takes extra space but if i include the same header
	(in this case) in many files and then try to link them together i get
	multiple definitioins errors...
	
	i thought #pragma interface and -fno-implement-inlines would handle
	this... but no. The amazing thing is that the actual programm doesnt
	even use any of the classes defined in the header, yet there is code
	generated...
	
	is there any way to fix this problem ?
	
	
	George Moshovitis
	gmosx AT theseas DOT ntua DOT gr
	
	(email response prefered...)

- Raw text -


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