home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #1 / NN_1993_1.iso / spool / comp / lang / modula3 / 1106 < prev    next >
Encoding:
Text File  |  1993-01-13  |  2.1 KB  |  54 lines

  1. Newsgroups: comp.lang.modula3
  2. Path: sparky!uunet!usc!cs.utexas.edu!sun-barr!decwrl!src.dec.com!src.dec.com!mjordan
  3. From: mjordan@src.dec.com (Mick Jordan)
  4. Subject: Re: Trouble with stdin on RS/6000
  5. Message-ID: <1993Jan13.040547.27180@src.dec.com>
  6. Sender: news@src.dec.com (News)
  7. Organization: DEC Systems Research Center
  8. References:  <1993Jan12.172641.40124@slate.mines.colorado.edu>
  9. Date: Wed, 13 Jan 93 04:05:47 GMT
  10. Lines: 42
  11.  
  12. In article <1993Jan12.172641.40124@slate.mines.colorado.edu>, lpratt@slate.mines.colorado.edu (Lorien Pratt) writes:
  13. |> Hi,
  14. |>   I'm trying to write a simple modula-3 program that takes input from the
  15. |> terminal.  Unfortunately, the program doesn't pause to wait for input from
  16. |> stdin; instead it receives an end of file indication.  If I echo the input
  17. |> to the program, however, it does work.  
  18.  
  19. There is nothing wrong with program and it works on a DECstation, so I would
  20. suspect something is amiss in the RS6000 runtime system. Lets hope an
  21. RS6000 M3 wizard can help.
  22.  
  23. |> I'd appreciate any pointers for how tell modula-3 to generate code to
  24. |> expect stdin from the terminal.  Thanks!
  25. |> 
  26.  
  27. For the record, the compiler knows nothing about the input/output system.
  28. Stdio, Rd and Wr are just modules like any other. The Stdio module
  29. arranges, as part of its initialisation code, to connect stdin/stdout/stderr
  30. to the Unix file descriptors of the same name.
  31.  
  32. Two improvements I would suggest to the program:
  33.  
  34. 1. Stdio.stdout is buffered and, perhaps to your suprise, the buffer is
  35.    not flushed by the '\n' character. You need to call "Wr.Flush(Stdio.stdout)"
  36.    either after each output or before any input requests.
  37.  
  38. 2. I find the concatenation of text literals and text values rather unreadable.
  39.    You can rewrite:
  40.  
  41.    Write("The sum of " & Fmt.Int(n1) & " And " & Fmt.Int(n2) & " is " &
  42.          Fmt.Int (n1 + n2) & ".\n");
  43.  
  44.    as:
  45.  
  46.    Write(Fmt.F("The sum of %s and %s is %s.\n", Fmt.Int(n1), Fmt.Int(n2),
  47.                Fmt.Int (n1 + n2)));
  48.  
  49.    which is about as close to "printf" as you can get without wiring
  50.    input/output into the compiler.
  51.  
  52. Mick Jordan
  53.              
  54.