home *** CD-ROM | disk | FTP | other *** search
- Xref: sparky comp.lang.c:12332 comp.programming:2319
- Newsgroups: comp.lang.c,comp.programming
- Path: sparky!uunet!gossip.pyramid.com!aquila.sni-usa.com!news.sni.de!uranium!josef
- From: Josef Moellers <mollers.pad@sni.de>
- Subject: Re: A LITTLE BRAINTEASER...
- Sender: josef@nixpbe.sni.de (Moellers)
- Message-ID: <josef.713800013@uranium>
- Date: Fri, 14 Aug 1992 13:46:53 GMT
- References: <aet.713608023@munagin> <Bswt31.7zC@research.canon.oz.au>
- Organization: Siemens Nixdorf Info.Sys. AG, Paderborn, Germany
- Lines: 52
-
- In <Bswt31.7zC@research.canon.oz.au> andy@research.canon.oz.au (Andy Newman) writes:
-
- >aet@mullian.ee.mu.OZ.AU (bert thompson) writes:
- >>hi!
- >>
- >>i have a small problem that's been bugging for a while now.
- >>
- >>here's a program that reverses input from the keyboard:
- >>
- >>main()
- >> char ch = getchar();
- > ^^^^^^^
- > NOT AGAIN!
- >> if (ch == EOF)
- >> ;
- >> else {
- >> main();
- >> putchar(ch);
- >> }
- >>}
- >>
- >>the interesting thing about the program is that it uses no data structures
- >>(structs, arrays, pointers, etc..), to do its thing. everything is thrown
- >>on the stack.
-
- >Another interesting thing about this program is that its broken!
-
- >So how may machines does this work on? Want to run it on something
- >without memory protection and let the little sucker recurse and
- >recurse...
-
- It'll run perfectly on systems that have signed characters!
- EOF usually is -1, so '\377' will expand to -1.
-
- >If that sounds cryptic remember....
-
- > getchar() returns an *int*, you char may not be able to store
- > EOF (which is v.often a -ve number).
-
- >Should we start a FFP (Frequently Found Problems?)
-
- Why not? I have been thinking about this for quite some time.
- More often than not, I find bugs that look too familiar!
- We (more or less regularly) do reviews on software that we write. A list
- of "things to check" would be very helpfull.
-
- >--
- >Andy Newman (andy@research.canon.oz.au) "int - God's own type"
- --
- | Josef Moellers | c/o Siemens Nixdorf Informationssysteme AG |
- | USA: mollers.pad@sni-usa.com | Abt. STO-XS 113 | Riemekestrasse |
- | !USA: mollers.pad@sni.de | Phone: (+49) 5251 835124 | D-4790 Paderborn |
-