tags:

views:

50

answers:

3

Every time I have to split a long string literal into two (or more) pieces, because it does not fit into a single line, I have to decide if I split the text before or after a space.

For example:

const char * long_text1 = "This is a long text, which does not fit "
                                "in one line";
/* or */
const char * long_text2 = "This is a long text, which does not fit"
                                " in one line";

I tend to use the first way, but I do not have a real reason for it. So I wonder is there any advantage to favor one of them? I know this questions tend to be coding style question, but that's not my intend. I only want to know if there is a convincing reason why one of those two ways might be preferable.

+1  A: 

There is no technical reason to prefer one over the other. As far as the compiler is concerned, those end up as the same string literal.

Carl Norum
Yes, I know. But have you a rule where to split? Or are you doing it at a random place?
quinmars
@quinmars, totally dependent on the string in question. As I say, there's no *technical* reason, so you can do whatever you want. If someone complains, poke him in the eye.
Carl Norum
A: 

I generally use the first method. Purely because I think starting a string segment with a space looks weird:

 " in one line";

It comes down to personal preference (or coding standard, if your job has one, and if it gets this picky).

Tim
+1  A: 

I prefer the second way as it's a little more obvious that the second and successive lines are continuations because they start with a space. I also line up the first double quotes:

const char * long_text2 = "This is a long text,"
                          " which does not fit"
                          " in one line";

And I split the line somewhere around the 70th character because lines longer than 80 chars are evil.

JayM
I'm with @JayM, although as others point out, this is really pretty subjective.
sblom