chris (11/08/82)
[1]); puts (lines[2]); for (lp = &lines[3]; *lp; ) puts (*lp++); } putq (s) char *s; { putchar (HT); putchar (DQUOTE); for (; *s != EOS; s++) { if (*s == BSLASH || *s == DQUOTE). Thus writing a self-reproducing C program is meaningless. Given a particular library of C I/O routines one could of course do it (e.g. with STDIO ). However someones else's IO library might allow shorter self-replications. For example, the OMCBIO library has a routine barf() which prints the source file containing a reference to it. Thus the program: #include <omcbio.h> main() { barf(); } [0;7m--More--[0m [K ...skipping 1 line NOTE: The above program actually compiles and runs correctly on my system (4.1 bsd). It must be run in the directory where it is compiled. The file omcbio.h contains the single line: #define barf() execlp("/bin/cat","cat",__FILE__,0) This has the nice feature of self-anihalation (overlay) immediatly after the self-replication. An obvious extension using fork() provides a tree of self-replicating programs. Article 95 (ihuxp.281): >From genradbo!decvax!harpo!ihps3!ihuxp!grg Wed Nov 3 21:04:01 1982 Subject: Self printing test. Newsgroups: net.lang.c (10 lines) More? [ynq] ? for commands. (10 lines) More? [ynq] Posting followup article to network. (To abort press DEL.) Please use reply ('r') instead unless your article is of general interest. Title: or (lp = lines; *lp; ) Newsgroups: net.lang.c Hit <return> to continue, DEL to abort: y compiles and runs correctly on my system (4.1 bsd). It must be run in the directory where it is compiled. The file omcbio.h contains the single line: #define barf() execlp("/bin/cat","cat",__FILE__,0) This has the nice feature of self-anihalation (overlay) immediatly after the self-replication. An obvious extension using fork() provides a tree of self-replicating programs. Article 95 (ihuxp.281): >From genradbo!decvax!harpo!ihps3!ihuxp!grg Wed Nov 3 21:04:01 1982 Subject: Self printing test. Newsgroups: net.lang.c (10 lines) More? [ynq] ? for commands. (10 lines) More? ?