Topic: templates optimisations (Was: (Correction/Clarification))


Author: Valentin Bonnard <bonnardv@pratique.fr>
Date: 1998/03/08
Raw View
Christopher Eltschka <celtschk@physik.tu-muenchen.de> writes:

> I've now found a valid example:
>
> template<class T> void f() {}
>
> void (*f1)() = f<int>;
> void (*f2)() = f<double>;
>
> assert(f1 != f2);

This optimisation can still be done. It's just of
matter of inserting n-1 NOP before the function code.

And return the appropriate pointer value when the address
of a function is taken.

I think that compilers/linkers could implement the
optimisation in a way which doesn't depends on the
fact that the functions are templates. I don't think
there is anything specialy difficult with that.

Of course the magic is that you have to create a
cooperation between the compiler and the linker,
and in C++ it's exceptionnal.

--

Valentin Bonnard                mailto:bonnardv@pratique.fr
info about C++/a propos du C++: http://www.pratique.fr/~bonnardv/
---
[ 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://reality.sgi.com/austern_mti/std-c++/faq.html              ]