4 your Bottoms only

Hum Four Bot Se Aaye Hain.... Mom Ka Dil Faulaadi Jigar Rakhte Hain.... Aagaaz -O- Anjaam Ki Parwaah Nahi.... Qayaamat Per Nazar Rakhte Hain.....

Thursday, July 28, 2005

Whao code!!

In 1994, during a meeting of the C++ standardization committe, Erwin Unruh discovered that templates can be used to compute something at compile time.He wrote a program that produced prime numbers.

The intriguing part of this exercise, however, was that the production of the prime numbers was performed by the compiler during the compilation process and not at run time. Specifically, the compiler produced a sequence of error messages with all prime numbers from two up to a certain configurable value. Although this program wasn't strictly portable (error messages aren't standardized),the program did show that template instantiation mechanism is a primitive recursive language that can perform nontrivial computations at compile time. This sort of compile-time computation that occurs through template instantiation is commonly called template metaprogramming.

He had used the Metaware compiler and coaxed it into issuing error messages that contain successive prime numbers. Here is the code that was circulated at a C++ committe meeting in 1994 (modified so that it now compiles on standard conforming compilers)

( Extract and code taken from the book C++ Templates )

I checked that error messages containing all the prime numbers are produced on SGI(cc,octane), HP(aCC,iophp1), linux(cc,hilbert). However, on AIX, SUN and windows, the instantiation is stopped only after the first error message. No more templates are instantiated and hence we get only one prime number.

1 Comments:

Blogger i said...

humko samjhao...

12:22 AM, July 29, 2005  

Post a Comment

<< Home