How to compile C++ program with templates to pure C or C++ program without templates?

P

PengYu.UT

Hi,

I heard that debug some C++ templates is very difficult. I'm wondering
whether it is possible to compile C++ program with templates to pure C
or C++ program without templates?

Best wishes,
Peng
 
G

Greg Comeau

I heard that debug some C++ templates is very difficult. I'm wondering
whether it is possible to compile C++ program with templates to pure C
or C++ program without templates?

The point of using templates is to not do that, since,
that's also difficult, generally speaking.
 
M

mlimber

Greg said:
The point of using templates is to not do that, since,
that's also difficult, generally speaking.

Errors associated with templates are notoriously verbose and often
cryptic (STLFilt not withstanding), and they make me wish I could have
the compiler emit the code generated from templates so I could more
easily see what was wrong. It would be similar to examining the output
of the preprocessor to debug macros. I don't know of any compiler that
does this, however.

Cheers! --M
 
E

E. Robert Tisdale

mlimber said:
Errors associated with templates
are notoriously verbose and often cryptic (STLFilt not withstanding),
and they make me wish [that] I could have the compiler
emit the code generated from templates
so [that] I could more easily see what was wrong.
It would be similar to examining the output of the preprocessor to debug macros.
I don't know of any compiler that does this, however.

Take a look at
The C++ Scalar, Vector, Matrix and Tensor class Library

http://www.netwood.net/~edwin/svmtl/

The genclass shell script

svmtl/bin/genclass

is a customized version of the original genclass script
written by Doug Lea.
We used this script for generic programming
before Bjarne had a proper implementation of templates.
It can't do all of the things that templates can do
but it does create human readable output that you can debug.

Most compilers have an option (gcc -E for example)
that displays the output from the C preprocessor (cpp)
before it is passed to the C++ compiler proper.
This output includes all of the macro substitutions
and allows you to debug macro definitions.
 
G

Greg Comeau

Errors associated with templates are notoriously verbose and often
cryptic (STLFilt not withstanding), and they make me wish I could have
the compiler emit the code generated from templates so I could more
easily see what was wrong. It would be similar to examining the output
of the preprocessor to debug macros. I don't know of any compiler that
does this, however.

Errors associated with other alternative similar things are also
notoriously verbose and often cryptic and don't even have something
such as STLfilt. This does not excuse either though and
I agree more needs to be done.
 
M

mlimber

E. Robert Tisdale said:
Take a look at
The C++ Scalar, Vector, Matrix and Tensor class Library

http://www.netwood.net/~edwin/svmtl/

The genclass shell script

svmtl/bin/genclass

is a customized version of the original genclass script
written by Doug Lea.
We used this script for generic programming
before Bjarne had a proper implementation of templates.
It can't do all of the things that templates can do
but it does create human readable output that you can debug.

Thanks! That might come in handy.
Most compilers have an option (gcc -E for example)
that displays the output from the C preprocessor (cpp)
before it is passed to the C++ compiler proper.
This output includes all of the macro substitutions
and allows you to debug macro definitions.

Right. Sorry for the ambiguity: I meant that I didn't know of any
compiler that generated code from templates. All the compilers I'm
familiar with can dump the output of the preprocessor.

Cheers! --M
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,480
Members
44,900
Latest member
Nell636132

Latest Threads

Top