This is kind of a weird behavior. Basically, I have this code:
stdout.printf("Enter some random number: ");
int number = int.parse(stdin.read_line());
stdout.printf(number.to_string());
stderr.printf("THIS IS AN ERROR!\n");
Now what's weird to me is that when I compile and run this code, I get this output:
Enter some random number: 2
THIS IS AN ERROR!
2user@host:...
But if I add a line that says stdout.printf("\n");
between the last two commands, I get this as in input:
Enter some random number: 2
2
THIS IS AN ERROR!
user@host
Why is this happening? Why is Vala outputting the number after the sterr.printf()
output in the first example and before in the second one? Shouldn't it just print 2THIS IS AN ERROR!
in the first example?
Vala is just using C's fprintf
underneath, which displays these semantics. Have a look at Why does printf not flush after the call unless a newline is in the format string?
You can call stdout.flush()
if you want.