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

  1. Xref: sparky comp.lang.c:12332 comp.programming:2319
  2. Newsgroups: comp.lang.c,comp.programming
  3. Path: sparky!uunet!gossip.pyramid.com!aquila.sni-usa.com!news.sni.de!uranium!josef
  4. From: Josef Moellers <mollers.pad@sni.de>
  5. Subject: Re: A LITTLE BRAINTEASER...
  6. Sender: josef@nixpbe.sni.de (Moellers)
  7. Message-ID: <josef.713800013@uranium>
  8. Date: Fri, 14 Aug 1992 13:46:53 GMT
  9. References: <aet.713608023@munagin> <Bswt31.7zC@research.canon.oz.au>
  10. Organization: Siemens Nixdorf Info.Sys. AG, Paderborn, Germany
  11. Lines: 52
  12.  
  13. In <Bswt31.7zC@research.canon.oz.au> andy@research.canon.oz.au (Andy Newman) writes:
  14.  
  15. >aet@mullian.ee.mu.OZ.AU (bert thompson) writes:
  16. >>hi!
  17. >>
  18. >>i have a small problem that's been bugging for a while now.
  19. >>
  20. >>here's a program that reverses input from the keyboard:
  21. >>
  22. >>main()
  23. >>    char ch = getchar();
  24. >        ^^^^^^^
  25. >    NOT AGAIN!
  26. >>    if (ch == EOF)
  27. >>        ;
  28. >>    else {
  29. >>        main();
  30. >>        putchar(ch);
  31. >>    }
  32. >>}
  33. >>
  34. >>the interesting thing about the program is that it uses no data structures
  35. >>(structs, arrays, pointers, etc..), to do its thing. everything is thrown
  36. >>on the stack.
  37.  
  38. >Another interesting thing about this program is that its broken!
  39.  
  40. >So how may machines does this work on? Want to run it on something
  41. >without memory protection and let the little sucker recurse and
  42. >recurse...
  43.  
  44. It'll run perfectly on systems that have signed characters!
  45. EOF usually is -1, so '\377' will expand to -1.
  46.  
  47. >If that sounds cryptic remember....
  48.  
  49. >    getchar() returns an *int*, you char may not be able to store
  50. >    EOF (which is v.often a -ve number).
  51.  
  52. >Should we start a FFP (Frequently Found Problems?)
  53.  
  54. Why not? I have been thinking about this for quite some time.
  55. More often than not, I find bugs that look too familiar!
  56. We (more or less regularly) do reviews on software that we write. A list
  57. of "things to check" would be very helpfull.
  58.  
  59. >-- 
  60. >Andy Newman (andy@research.canon.oz.au)        "int - God's own type"
  61. -- 
  62. | Josef Moellers        | c/o Siemens Nixdorf Informationssysteme AG  |
  63. |  USA: mollers.pad@sni-usa.com    | Abt. STO-XS 113       | Riemekestrasse   |
  64. | !USA: mollers.pad@sni.de    | Phone: (+49) 5251 835124 | D-4790 Paderborn |
  65.