home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #27 / NN_1992_27.iso / spool / comp / lang / cplus / 16391 < prev    next >
Encoding:
Text File  |  1992-11-17  |  1.5 KB  |  61 lines

  1. Path: sparky!uunet!wupost!gumby!yale!yale.edu!spool.mu.edu!agate!doc.ic.ac.uk!uknet!mcsun!ub4b!alcbel!ta7s49.alcbel.be
  2. From: ldup@ta7s49.alcbel.be (Luc Duponcheel)
  3. Newsgroups: comp.lang.c++
  4. Subject: self-reproducing C++ program
  5. Message-ID: <1919@alcbel.be>
  6. Date: 16 Nov 92 09:02:51 GMT
  7. Sender: ldup@alcbel.be
  8. Organization: Alcatel Bell Telephone, Antwerpen, Belgium
  9. Lines: 50
  10.  
  11. Consider the following 'self-reproducing' C++ program 
  12.  
  13. ******begin 'prog.c'***************
  14.  
  15. #include<iostream.h>
  16. 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;}
  17.  
  18. ******end 'prog.c'***************
  19.  
  20.  
  21. Do the following :
  22.  
  23. $ CC prog.c
  24. $ a.out > PROG.c
  25. $ diff prog.c PROG.c
  26. $
  27.  
  28.  
  29. Can somebody find a SHORTER 'self-reproducing' C++ program?
  30.  
  31.  
  32. NOTE :
  33.  
  34.  
  35. Of course one can make a shorter 'self-reproducing' C++ program
  36. using a user defined include file as follows :
  37.  
  38.  
  39. ******begin 'prog.c'***************
  40.  
  41. #include"x.h"
  42. main(){cout<<x;}
  43.  
  44. ******end 'prog.c'***************
  45.  
  46. ******begin 'x.h'***************
  47.  
  48. #include<iostream.h>
  49. char*x="#include\"x.h\"\nmain(){cout<<x;}\n";
  50.  
  51. ******end 'x.h'***************
  52.  
  53. but this is 'cheating'.
  54.  
  55.  
  56. BTW :
  57.  
  58. if you send a shorter program to comp.lang.c++, then please also send
  59. it directly to me by email (ldup@alcbel.be) since I do not read comp.lang.c++
  60. very often.
  61.