Is there any flag for gcc
or g++
that turns the buffering off for stdout
?
Like python -u
turns off buffering of stdout
,stdin
and stderr
in python.
Asked
Active
Viewed 402 times
0

perror
- 7,071
- 16
- 58
- 85

Sardeep Lakhera
- 309
- 4
- 15
-
6Not a gcc flag, but see [How to turn off buffering of stdout in C](http://stackoverflow.com/questions/7876660/how-to-turn-off-buffering-of-stdout-in-c). – Philip Kendall May 05 '13 at 19:06
-
I want to turn off buffering through gcc not through c. – Sardeep Lakhera May 05 '13 at 19:19
-
2@c4rbon, that's not the compiler's job. That's your code's job. – Mat May 05 '13 at 19:25
-
@Mat,i thought if it is available in python, it might be available in gcc. – Sardeep Lakhera May 05 '13 at 19:30
-
@c4rbon: your comparing apples and oranges. – Mat May 05 '13 at 19:32
1 Answers
3
GCC, as a compiler, only generates an executable. It has no real knowledge of buffering or even of streams. Only the C runtime knows what your stdout
and stderr
are. You need to tell the C runtime, at obviously runtime, to disable buffering.
By comparison, the Python runtime is an interpreter. As an interpreter, it is the one to set up your streams and can disable the buffering if you ask it to.

3Doubloons
- 2,088
- 14
- 26