home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #18 / NN_1992_18.iso / spool / comp / os / os2 / programm / 4338 < prev    next >
Encoding:
Text File  |  1992-08-19  |  2.9 KB  |  88 lines

  1. Newsgroups: comp.os.os2.programmer
  2. Path: sparky!uunet!brunix!brunix!wcn
  3. From: wcn@cs.brown.edu (Wen-Chun Ni)
  4. Subject: Re: Question and problem with GCC/2
  5. Message-ID: <1992Aug20.031405.20353@cs.brown.edu>
  6. Sender: news@cs.brown.edu
  7. Organization: Brown University Department of Computer Science
  8. References: <1992Aug19.212328.15304@talon.ucs.orst.edu> <1992Aug20.010531.28610@mdd.comm.mot.com>
  9. Distribution: na
  10. Date: Thu, 20 Aug 1992 03:14:05 GMT
  11. Lines: 75
  12.  
  13. If gcc/2 is going to be ANSI-compliant, I think there are something wrong 
  14. here.  According to W Richard Stevens' book "Advanced Programming in the
  15. Unix Environment," pp 123, about "stdio" library:
  16.  
  17.     ANSI C requires the following buffering characteristics:
  18.  
  19.      1. Standard input and standard output are fully buffered, if
  20.         and only if they do not refer to an interactive device.
  21.      2. Standard error is never fully buffered.
  22.  
  23.  
  24. I've tried all the I/O operations under both SunOS and my Linux and
  25. they comply to the above requirement. While the OS/2 gcc/2 doesn't
  26. seems to get it right. Somebody mentioned that "buffering" was 
  27. supposed to be ANSI-compliant, but I think it's kind of misunderstood.
  28.  
  29.  
  30. Wen-Chun Ni
  31.  
  32. In article <1992Aug20.010531.28610@mdd.comm.mot.com> lmorris@mdd.comm.mot.com (Larry Morris) writes:
  33. >In <1992Aug19.212328.15304@talon.ucs.orst.edu> hilmera@ucs.orst.edu (Andrew Hilmer) writes:
  34. >
  35. >>Compiler: gcc/2 2.1
  36. >>Problem: problem and question about gcc/2
  37. >
  38. >...
  39. >
  40. >>/*
  41. >>  This program takes the input of two numbers, one
  42. >>  integer, one floating point, and prints them back out.
  43. >>*/
  44. >
  45. >>#include <stdio.h>
  46. >
  47. >>main()
  48. >>{
  49. >>  int x;
  50. >>  float y;
  51. >
  52. >>/*  fflush(stdin); */
  53. >>  printf("This is my first C program.\n");
  54. >>  printf("Enter an integer: ");
  55. >>  scanf("%d", &x);
  56. >>  printf("Enter a floating point number: ");
  57. >>  scanf("%f", &y);
  58. >>  printf("The value stored in x is %d\n", x);
  59. >>  printf("The value stored in y is %f\n", y);
  60. >>}
  61. >
  62. >...
  63. >
  64. >>When run, it prints nothing but a line or two and a blinking cursor.
  65. >>As a shot in the dark, I entered 3, hit enter (got another big
  66. >>nothing), then entered 93.9 and hit enter.
  67. >
  68. >Read  the FAQ.  Nothing says when stdout will flush unless you specify it.
  69. >The program did exactly as requested. 
  70. >    printf() some stuff   --  it gets buffered to stdout
  71. >    scanf() some stuff    --  you typed 3
  72. >    printf() some more    --  stdout buffers some more
  73. >    scanf() some more     --  you typed 93.9
  74. >    exit()        -- stdout gets flushed at exit and you see the printfs()
  75. >
  76. >If you want to handle the flushes yourself, just fflush(stdout)  before each
  77. >of the scanfs().  Takes full advantage of any buffering and gets you exactly
  78. >what you want.
  79. >
  80. >
  81. >-- 
  82. >Internet:    <lmorris@mdd.comm.mot.COM>   |  Larry Morris
  83. > ...uw-beaver!sunup-----\                 |  Motorola/Mobile Data Division
  84. > ...uunet-----------------!mdisea!lmorris |  19807 North Creek Parkway
  85. > ...van-bc!mdivax1------/                 |  Bothell, WA  (206) 487-5810
  86.  
  87.  
  88.