Adjacent string literals are concatenated, and this is useful in two ways: macros that concatenate strings and render multi-line string literals , such as you already above. Compare how this code would look different:
char const help_message[] = "Usage: %s [options] files ...\n\nOptions include:\n --verbose -v Be verbose\n --help -h Print this help message\n --output -o Specify output file\n\n";
, . , , , , , '\n', . .
:
#define STRINGIZE_(v) #v
#define STRINGIZE(v) STRINGIZE_(v)
#define LOCATION __FILE__ ":" STRINGIZE(__LINE__)
#define MY_ASSERT(expr) do { \
if (!(expr)) \
some_function(LOCATION ": assertion failed in " \
__PRETTY_FUNCTION__ ": " #expr); \
} while (0)
( , GCC __PRETTY_FUNCTION__, , , "" , .)
, , :
# (## , )- ,
"filename.c:__LINE__" - do-while if-else , ,
if-else:
if (cond) MY_ASSERT(blah);
else other();
:
if (cond) do { ... } while(0);
else other();
:
if (cond) if (...) ...;
else other();
:
if (cond) {
if (...) {
...;
}
else {
other();
}
}
Roger Pate