Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > C++ Moderated > Re: Meyers effe...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 7 of 9 Topic 9501 of 9807
Post > Topic >>

Re: Meyers effective C++, templates, np-complete

by Edward Rosten <Edward.Rosten@[EMAIL PROTECTED] > Apr 15, 2008 at 12:34 PM

On Apr 14, 9:22 pm, Todd Mars <tamn...@[EMAIL PROTECTED]
> wrote:
> Scott Meyers in Effective C++ at the start of the templates section
> says that C++ templates are np-complete in the compiler processing.
> Does this mean that the use of templates can cause the compile to
> execute for an infinite loop or near infinite loop?
> Todd.

Templates are turing complete, which means you can execute an infinite
loop (up to the compilers recursion depth). For instance, this:

template<int i> struct Infinite
{
	static const int num = Infinite<i>::num;
};

static const int loop = Infinite<0>::num;

causes my compiler to run out of memory and die.

-Ed

-- 
(You can't go wrong with psycho-rats.)(http://mi.eng.cam.ac.uk/~er258)

/d{def}def/f{/Times s selectfont}d/s{11}d/r{roll}d f 2/m{moveto}d -1
r 230 350 m 0 1 179{ 1 index show 88 rotate 4 mul 0 rmoveto}for/s 12
     d f pop 235 420 translate 0 0 moveto 1 2 scale show showpage


      [ See http://www.gotw.ca/resources/clcm.htm
for info about ]
      [ comp.lang.c++.moderated.    First time posters: Do this! ]
 




 9 Posts in Topic:
Meyers effective C++, templates, np-complete
Todd Mars <tamnt54@[EM  2008-04-14 21:22:01 
Re: Meyers effective C++, templates, np-complete
Carl Barron <cbarron41  2008-04-15 12:28:24 
Re: Meyers effective C++, templates, np-complete
=?ISO-8859-1?Q?Daniel_Kr=  2008-04-15 12:29:15 
Re: Meyers effective C++, templates, np-complete
Marcin.Barczynski@[EMAIL   2008-04-15 12:32:41 
Re: Meyers effective C++, templates, np-complete
Thomas Richter <thor@[  2008-04-15 12:31:09 
Re: Meyers effective C++, templates, np-complete
Mathias Gaunard <loufo  2008-04-15 12:32:35 
Re: Meyers effective C++, templates, np-complete
Edward Rosten <Edward.  2008-04-15 12:34:17 
Re: Meyers effective C++, templates, np-complete
"Martin T." <  2008-04-15 12:43:13 
Re: Meyers effective C++, templates, np-complete
Vidar Hasfjord <vattil  2008-04-16 11:38:44 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Sat Jul 19 19:45:42 CDT 2008.