
The following code will on Linux print three strings each followed by a NULL byte: module Main where putStr0 = putStr $ s ++ "\0" main = do putStr0 "Hello" putStr0 "Hello" putStr0 "Hello" On Windows however it will print nothing! In order to trigger printing I have to change the definition of putStr0 to putStr0 = putStr (s ++ "\0") >> hFlush stdout Is this difference in behaviour due to a bug in GHC on Windows or just a quirkiness of the platform? /M

2008/2/12 Magnus Therning
The following code will on Linux print three strings each followed by a NULL byte:
module Main where
putStr0 = putStr $ s ++ "\0"
main = do putStr0 "Hello" putStr0 "Hello" putStr0 "Hello"
On Windows however it will print nothing! In order to trigger printing I have to change the definition of putStr0 to
putStr0 = putStr (s ++ "\0") >> hFlush stdout
Is this difference in behaviour due to a bug in GHC on Windows or just a quirkiness of the platform?
I can't directly answer, but a way to find out would be to try the
same thing in C.
It seems to me that, while Linux implicitly flushes streams on exit,
Windows is failing to do so. So try the same output in C, with and
without fflush, and.. you'll see.
A program to do this follows for your convenience.
----
#include

Hi
The following code will on Linux print three strings each followed by a NULL byte:
module Main where
putStr0 = putStr $ s ++ "\0"
main = do putStr0 "Hello" putStr0 "Hello" putStr0 "Hello"
On Windows however it will print nothing!
You missed out an s in putStr0, which causes it not to compile. When I add the s, and try on Windows XP with GHC 6.8.1 it works perfectly and prints 3 strings with null bytes. Can you still replicate this? If so, what specific details. Thanks Neil
participants (4)
-
Magnus Therning
-
Neil Mitchell
-
Roberto Zunino
-
Svein Ove Aas