@@ -112,10 +112,13 @@ showCStr s = '"' : foldr ((++) . showChar) "\"" s
112112 showChar '"' = "\\\""
113113 showChar '\\' = "\\\\"
114114 showChar c
115− | ord c < 0x10 = "\\x0" ++ showHex (ord c) ""
116− | ord c < 0x20 = "\\x" ++ showHex (ord c) ""
115+ -- Note: we need the double quotes around the codes because otherwise
116+ -- "\n3" would get encoded as "\x0a3", which is incorrect.
117+ -- Instead, we opt for "\x0a""3" and let the C compiler deal with it.
118+ | ord c < 0x10 = "\"\"\\x0" ++ showHex (ord c) "\"\""
119+ | ord c < 0x20 = "\"\"\\x" ++ showHex (ord c) "\"\""
117120 | ord c < 0x7f = [c] -- 0x7f = \DEL
118− | ord c < 0x100 = "\\x" ++ showHex (ord c) ""
121+ | ord c < 0x100 = "\"\"\\x" ++ showHex (ord c) "\"\""
119122 | otherwise = error $ "non-8-bit character in string literal: " ++ show c
120123
121124bcc :: Int -> BC -> String