Escape codes are not 100% portable

Jens Bauer via Digitalmars-d digitalmars-d at puremagic.com
Thu Apr 2 04:42:48 PDT 2015


> any compiler that does the second is broken and should be 
> fixed. DMD is not broken.

If the byte values for \n and \r are clearly given as \r = 13 
(0x0d) and \n = 10 (0x0a), instead of \n = newline and \r = 
carriage return, then I agree.

However, I know 5 compilers, which do swap \r and \n, because the 
platforms defines newline to be 13 and return to be 10.

Perhaps it will not make a big difference which is which; I only 
feel that it's my duty to point out a potential problem.

To make sure the compiler will read all source files correctly, 
it should actually handle the following sequences:
0x0a
0x0d
0x0d0a

-Because if a file was copied to the platform where \r and \n are 
"reversed", then this file would not build if each line only ends 
by 0x0a.
On the other hand, if a file was copied to a platform, where \r = 
13 and \n = 10, and the file contains lines ending in 0x0d, then 
this compiler would not be able to build the file.
The last combination is the \r\n, which normally would be 0x0d0a. 
If the compiled program expects \r\n and \r is 10 and \n is 13, 
then files written by a DOS or Windows editor could be parsed 
incorrectly.


More information about the Digitalmars-d mailing list