Re:C Macro Tips and Tricks
by davvid on Sunday January 02, 2011 @05:30PM
(#2061323)
From the article:
"""
It's a little-known feature of C that if you put two string literals next to each other in the source code, they get concatenated:
char *helloworld = "hello, " "world!";
"""
That's a good tip that actually works in other languages too. It helps in Python, for example, when creating long strings. Wrapping parentheses around the string and using the quote-continuation rule makes it nice and easy to read.
For example:
foo = ('hello world this is '
'a long string')
is better than:
foo = 'hello world this is ' + \
'a long string'
...for two reasons. It avoids string concatenation (the "+" operator) and it avoids the backslash.
""" It's a little-known feature of C that if you put two string literals next to each other in the source code, they get concatenated:
"""That's a good tip that actually works in other languages too. It helps in Python, for example, when creating long strings. Wrapping parentheses around the string and using the quote-continuation rule makes it nice and easy to read.
For example:
is better than: ...for two reasons. It avoids string concatenation (the "+" operator) and it avoids the backslash.