Quines

Stewart Gordon smjg_1998 at yahoo.com
Mon Jul 10 07:25:57 PDT 2006


BCS wrote:
> @run time
> 
> void main(){printf(a~\140~a~\140";");}char[]a=`void 
> main(){printf(a~\140~a~\140";");}char[]a=`;

http://smjg.port5.com/wwwep/quines/d.html

Somewhere I've got one similar to the last of these but using writef.

> @compile time   =op
> 
> const char[]a=`const char[]a=`;const char[]b=`;const char[]`;const 
> char[]c=`;pragma(msg,a~\140~a~\140~b~"b=\140"~b~\140~b~"c=\140"~c~\140~c);`;pragma(msg,a~\140~a~\140~b~"b=\140"~b~\140~b~"c=\140"~c~\140~c); 

Writing code to do stuff at compile time like this is an interesting 
idea.  I've seen the C preprocessor used for this:

http://www.99-bottles-of-beer.net/language-c-c++-preprocessor-115.html

Stewart.



More information about the Digitalmars-d-learn mailing list