home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!utcsri!devnull
- Newsgroups: alt.hackers
- From: flaps@dgp.toronto.edu (Alan J Rosenthal)
- Subject: Re: Self Printing Program, revisited
- Message-ID: <1992Sep4.083327.15563@jarvis.csri.toronto.edu>
- References: <9lm-wK-@engin.umich.edu>
- Date: 4 Sep 92 12:33:28 GMT
- Approved: hyoop
- Lines: 41
-
- {Note: When you get bored reading this article, skip to the end.}
-
- positron@engin.umich.edu (Jonathan Scott Haas) writes:
- >Awhile back, there was talk about how to write a program whose
- >output would be the program itself. Here's my program, written
- >in C, but I think perhaps it "cheats" a bit.
- [reads its own source code from a file]
-
- Well, is "cat" a self printing program because you can do
- cat /usr/src/bin/cat.c
- ? "Cat" is not an extremely exciting or novel program. Your program is less
- exciting than cat.
-
- Something similar but a little cooler is something in a microcomputer basic
- environment which uses peeks to list whatever program is in memory, just like
- the "list" command does, and thus lists itself.
-
- However, none of these programs have the essential ingredient of a self-
- printing program, which is that the program contains itself in a certain
- sense. In these programs, they have to go to some external area and look up
- the source. For example, in your program, if you compile it and then delete
- the source it will stop functioning. A proper self-printing program won't have
- this failing.
-
- Here's a program which prints itself, except that it's somewhat buggy and
- sometimes dumps core instead.
-
-
- #include <signal.h>
-
- int main()
- {
- kill(getpid(), SIGBUS);
- }
-
-
- --
-
- Why don't we discuss cool variant problems? Did anyone like my pair of
- programs in different programming languages each of which output the other?
- What are some other good variant problems? Post or e-mail.
-