Re: Avoiding C++ Templates In Cipher Implementation

From: Benjamin Goldberg (ben.goldberg_at_hotpop.com)
Date: 06/13/03


Date: Thu, 12 Jun 2003 21:14:42 -0400

Ernst Lippe wrote:
[snip]
> Many people see templates as a form of glorified macro's. Even though
> I am not a great fan of macro's I have to admit that their semantics
> are not really difficult. Macro's can be described as a simple textual
> operation on your source text that can then be used in the next phases
> of the compilation. Templates are completely different, unlike macro's
> it is not possible to write a simple program that removes the
> templates from your program and gives you back a semantically
> equivalent template-free program. In theory it may be possible to
> write such a program,

In theory, any cfront-style C++ compiler is such a program :)

Alas, in practice, many of them have *very* incomplete template
handling... last that I heard, anyway. My knowledge on this is quite
dated, though, and there may exist a more complete cfront compiler.

> but because templates are turing complete you
> cannot guarantee that this program will always terminate.

Isn't this true even with a regular C++ compiler?

Out of curiosity, what happens if you write a program which has:

   template <int i> struct foo;
   template <int i> { struct foo<i+1> bar; };
   int main(int argc, char *argv[]) {
      foo<0> quux;
      return 0;
   }

With a normal (non-cfront) C++ compiler, what happens?

-- 
$a=24;split//,240513;s/\B/ => /for@@=qw(ac ab bc ba cb ca
);{push(@b,$a),($a-=6)^=1 for 2..$a/6x--$|;print "$@[$a%6
]\n";((6<=($a-=6))?$a+=$_[$a%6]-$a%6:($a=pop @b))&&redo;}


Relevant Pages

  • Re: why still use C?
    ... > to be at the mercy of the compiler and its designer, ... as a programmer I am no ... > program using templates and expect it to work identically on different ... > in mind that a programming language is a tool to make programs. ...
    (comp.lang.c)
  • Re: [C++] Casting void* pointers within different scope
    ... in the use of class objects and templates, ... |> template<class Key, class PMF> ... | In those cases where the compiler has not enough information to deduce the ... | Locate template based on what you pass to the constructor. ...
    (alt.comp.lang.learn.c-cpp)
  • Re: Delphi to Visual Studio Conversion Project
    ... Templates are in fact really compiled at the moment they are used. ... what the constraints specify, i.e. you can only cast the type to ... When you compile the generics, all the capabilites are already tested ... compiler checked before use. ...
    (borland.public.delphi.non-technical)
  • Re: why still use C?
    ... > simply down the callstack which is more readable than gotos, ... The nice thing about exceptions is that the code throwing it shouldn't ... My latest try on doing something with templates was with a C++ compiler ...
    (comp.lang.c)
  • Re: Is export "useless and broken"?
    ... since the compiler will need to precompile it ... If it's your own templates, ... >> that namespaces can't address. ... I'll agree on the macro issue, ...
    (comp.lang.cpp)