printf(
"for %s\n"
" mat %s\n"
" ting %s\n"
" string %s\n",
param1,
param2,
param3,
param4);
vs.
printf(
"for %s\n"
" mat %s\n"
" ting %s\n"
" string %s\n"
,param1
,param2
,param3
,param4);
While the latter one looks strange, uncomfortable, even
icky, it has certain advantages, namely better field inserting ability from both ends:
1. Insert another string field to the end
First mode, step-by-step
diagram:
Step 1:
printf(
"for %s\n"
" mat %s\n"
" ting %s\n"
" string %s\n" <- erase ','
param1,
param2,
param3,
param4);
Step 2:
printf(
"for %s\n"
" mat %s\n"
" ting %s\n"
" string %s\n"
" addition %s\n" <-- add the actual textfield
param1,
param2,
param3,
param4);
Step 3:
printf(
"for %s\n"
" mat %s\n"
" ting %s\n"
" string %s\n"
" addition %s\n", <-- add the ','
param1,
param2,
param3,
param4);
vs.
Step 1:
printf(
"for %s\n"
" mat %s\n"
" ting %s\n"
" string %s\n"
" addition %s\n" <-- add the string
,param1
,param2
,param3
,param4);
As you can see, the second
method saves you the trouble of removing ',' and re-entering it in another place.
2. Adding another field in the end of parameter list.
First method, step-by-step diagram:
Step 1:
printf(
"for %s\n"
" mat %s\n"
" ting %s\n"
" string %s\n",
param1,
param2,
param3,
param4
); <-- drop ');' to the next line
Step 2:
printf(
"for %s\n"
" mat %s\n"
" ting %s\n"
" string %s\n",
param1,
param2,
param3,
param4, <-- add ','
);
Step 3:
printf(
"for %s\n"
" mat %s\n"
" ting %s\n"
" string %s\n",
param1,
param2,
param3,
param4,
param5); <-- add the parameter
vs.
Step 1:
printf(
"for %s\n"
" mat %s\n"
" ting %s\n"
" string %s\n"
,param1
,param2
,param3
,param4
); <-- drop the ');'
Step 2:
printf(
"for %s\n"
" mat %s\n"
" ting %s\n"
" string %s\n"
,param1
,param2
,param3
,param4
,param5); <-- add the parameter
Now, it could be argued that the first method's steps 1 and 2 could be merged by sequential ',\n'. This is true, yet for some reason it appears easier to forget it and changing line can be very burdensome.
Conclusion: Use ,-prefixed to minimize the effort of updating the lists.
Notes: Some ancient compilers might not like the "string" whitespace "string" construct. All decent compilers of course merge it, but for older compilers typical inline multiline string construct format would be as following:
printf("\
something\n\
something more\n\
yet something more\n\
",
param1,
param2,
param3);
The above approach is neither bulletproof; some DOS compilers, namely,
Cygwin-GCC for
Win32, can't handle that properly because of
DOS 0x0d 0x0a bug. However, the above approach forces you to use second method as applied in section 1.