Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

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

57 views
Skip to first unread message

Peng...@gmail.com

unread,
Oct 12, 2005, 10:50:23 AM10/12/05
to
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

Greg Comeau

unread,
Oct 12, 2005, 10:53:41 AM10/12/05
to
In article <1129128623.5...@g14g2000cwa.googlegroups.com>,

The point of using templates is to not do that, since,
that's also difficult, generally speaking.
--
Greg Comeau / Celebrating 20 years of Comeauity!
Comeau C/C++ ONLINE ==> http://www.comeaucomputing.com/tryitout
World Class Compilers: Breathtaking C++, Amazing C99, Fabulous C90.
Comeau C/C++ with Dinkumware's Libraries... Have you tried it?

mlimber

unread,
Oct 12, 2005, 12:30:21 PM10/12/05
to
Greg Comeau wrote:
> In article <1129128623.5...@g14g2000cwa.googlegroups.com>,
> Peng...@gmail.com <Peng...@gmail.com> wrote:
> >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.

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. Robert Tisdale

unread,
Oct 12, 2005, 12:52:07 PM10/12/05
to
mlimber wrote:

> 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.

Greg Comeau

unread,
Oct 12, 2005, 2:33:19 PM10/12/05
to
In article <1129134621.8...@g44g2000cwa.googlegroups.com>,

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.

mlimber

unread,
Oct 12, 2005, 2:47:22 PM10/12/05
to
E. Robert Tisdale wrote:

> mlimber wrote:
>
> > 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.

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

0 new messages