views:

5564

answers:

7

It occasionally tells me:

"The line endings in the following files are not consistent. Do you want to normalize the line endings?"

Then gives me a drop down with different standards or something, Windows, Mac, Unix, and a couple Unicode.

What the hell does this mean and what is going to happen if I click 'Yes'?

+4  A: 

What that usually means is that you have lines ending with something other than a carriage return/line feed pair. It often happens when you copy and paste from a web page into the code editor.

Since you're developing in Visual Studio, you'll obviously want to choose "Windows" from the drop down. :-)

Ken White
how does the line end without a carriage return... ?
shogun
With just a line feed.
Ryan, a line feed is just a non-printable char value (you can't see it). A valid end of line in Windows is a two char pair (ASCII 13 for carriage return, 10 for line feed - 0x0D 0x0A in hex). As monowerker said below, different OSes use different line endings.
Ken White
So why the flip does visual studio care how the lines end, it apparently recognizes all the different types, it should just be happy and shut up.
shogun
I guess because it's a Windows editor? Other than that, I have no idea; I guess you'd have to ask Microsoft. FYI, though, I use Delphi a lot, and it's editor, while it doesn't show an error message, has problems matching code execution points when debugging if the line ends are wrong.
Ken White
You'd think that, by now, they would have implemented some code in their paste handling routines that goes through the newly added text and fixes up 'oddball' (non-Windows) line endings automatically. Sheesh! How hard can that be?
RobH
Ah, but what if you're just using VS to fix something that isn't for Windows? Quick fix on a Linux utility or something that's straight C/C++, and you don't want CRLFs added? Wait-now you want MS to read your mind and know which to use? <g> The VS team is wrong either way, aren't they? Sheesh!
Ken White
Oh snap Ken, you're right, if I happen to be editing some files that I plan to compile in Linux and I know the compiler will choke and die if it doesn't have exactly the line endings that it needs then I will have been glad VS let me choose... THANK YOU!
shogun
+1  A: 

Some lines end with \n
Some other lines end with \r\n
VS suggests you to make all lines end the same.

Alex Reitbort
+2  A: 

The file you are editing have been edited with some other editor that does not use the same line endings resulting in a file with mixed line endings.

The ASCII characters in use for line endings are:

CR, Carriage Return
LF, Line Feed

Windows = CRLF
Mac = CR
Unix = LF

monowerker
+1  A: 

The Wikipedia article on this might help you out

Richard Ev
+2  A: 

It means that, for example, some of your lines of text with a <Carriage Return><Linefeed> (the Windows standard), and some end with just a <Linefeed> (the Unix standard).

If you click 'yes' these the end-of-lines in your source file will be converted to have all the same format.

This won't make any difference to the compiler (because end-of-lines count as mere whitespace), but it might make some difference to other tools (e.g. the 'diff' on your version control system).

ChrisW
+1  A: 

There'a an add-in for Visual Studio 2008 that converts the end of line format when a file is saved. You can download it here: http://grebulon.com/software/stripem.php

This can help when you get the "inconsistent line endings" error from svn.
Kurt
+1  A: 

It's not just VS... it'd be any tools that read the files... compilers, linkers, ... that would have to be able to handle it. In general (for software development) we accept the multiplatform line ending issue but let the version control software deal with it.

Peter Y
I agree. Best to let your SCM system do it. If you are using svn, see also http://stackoverflow.com/questions/15687/how-can-i-convert-all-line-endings-to-crlf-lf-or-cr-during-svn-operations
Kurt