home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #18 / NN_1992_18.iso / spool / comp / lang / c / 12310 < prev    next >
Encoding:
Internet Message Format  |  1992-08-13  |  1.4 KB

  1. Xref: sparky comp.lang.c:12310 comp.programming:2308
  2. Newsgroups: comp.lang.c,comp.programming
  3. Path: sparky!uunet!munnari.oz.au!metro!mama!andy
  4. From: andy@research.canon.oz.au (Andy Newman)
  5. Subject: Re: A LITTLE BRAINTEASER...
  6. Message-ID: <Bswt31.7zC@research.canon.oz.au>
  7. Sender: news@research.canon.oz.au
  8. Organization: Canon Information Systems Research Australia
  9. References: <aet.713608023@munagin>
  10. Date: Thu, 13 Aug 1992 06:37:48 GMT
  11. Lines: 37
  12.  
  13. aet@mullian.ee.mu.OZ.AU (bert thompson) writes:
  14. >hi!
  15. >
  16. >i have a small problem that's been bugging for a while now.
  17. >
  18. >here's a program that reverses input from the keyboard:
  19. >
  20. >main()
  21. >    char ch = getchar();
  22.         ^^^^^^^
  23.     NOT AGAIN!
  24. >    if (ch == EOF)
  25. >        ;
  26. >    else {
  27. >        main();
  28. >        putchar(ch);
  29. >    }
  30. >}
  31. >
  32. >the interesting thing about the program is that it uses no data structures
  33. >(structs, arrays, pointers, etc..), to do its thing. everything is thrown
  34. >on the stack.
  35.  
  36. Another interesting thing about this program is that its broken!
  37.  
  38. So how may machines does this work on? Want to run it on something
  39. without memory protection and let the little sucker recurse and
  40. recurse...
  41.  
  42. If that sounds cryptic remember....
  43.  
  44.     getchar() returns an *int*, you char may not be able to store
  45.     EOF (which is v.often a -ve number).
  46.  
  47. Should we start a FFP (Frequently Found Problems?)
  48. -- 
  49. Andy Newman (andy@research.canon.oz.au)        "int - God's own type"
  50.