home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!wupost!gumby!yale!yale.edu!spool.mu.edu!agate!doc.ic.ac.uk!uknet!mcsun!ub4b!alcbel!ta7s49.alcbel.be
- From: ldup@ta7s49.alcbel.be (Luc Duponcheel)
- Newsgroups: comp.lang.c++
- Subject: self-reproducing C++ program
- Message-ID: <1919@alcbel.be>
- Date: 16 Nov 92 09:02:51 GMT
- Sender: ldup@alcbel.be
- Organization: Alcatel Bell Telephone, Antwerpen, Belgium
- Lines: 50
-
- Consider the following 'self-reproducing' C++ program
-
- ******begin 'prog.c'***************
-
- #include<iostream.h>
- char*a="\"\\char*a=",*b="#include<iostream.h>",*c="main(){cout<<b<<endl<<a+2<<*a<<a[1]<<*a<<a[1]<<a[1]<<a+2<<*a<<','<<'*'<<'b'<<'='<<*a<<b<<*a<<','<<'*'<<'c'<<'='<<*a<<c<<*a<<';'<<c<<endl;}";main(){cout<<b<<endl<<a+2<<*a<<a[1]<<*a<<a[1]<<a[1]<<a+2<<*a<<','<<'*'<<'b'<<'='<<*a<<b<<*a<<','<<'*'<<'c'<<'='<<*a<<c<<*a<<';'<<c<<endl;}
-
- ******end 'prog.c'***************
-
-
- Do the following :
-
- $ CC prog.c
- $ a.out > PROG.c
- $ diff prog.c PROG.c
- $
-
-
- Can somebody find a SHORTER 'self-reproducing' C++ program?
-
-
- NOTE :
-
-
- Of course one can make a shorter 'self-reproducing' C++ program
- using a user defined include file as follows :
-
-
- ******begin 'prog.c'***************
-
- #include"x.h"
- main(){cout<<x;}
-
- ******end 'prog.c'***************
-
- ******begin 'x.h'***************
-
- #include<iostream.h>
- char*x="#include\"x.h\"\nmain(){cout<<x;}\n";
-
- ******end 'x.h'***************
-
- but this is 'cheating'.
-
-
- BTW :
-
- if you send a shorter program to comp.lang.c++, then please also send
- it directly to me by email (ldup@alcbel.be) since I do not read comp.lang.c++
- very often.
-