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.

As always, it all depends on whether you use a decent text editor. With the magic of "insert mode", even complex editing tasks like adding parameters become easier!

For convenience, I've inserted a `!' sign to denote the location of the cursor...

Step 1:

  printf(      
         "for %s\n"
         "   mat %s\n"
         "      ting %s\n"
         "           string %s\n"!,   ← start before ','
         param1,
         param2,
         param3,
         param4);

Step 2:

Type "newline" and the additional string; the comma moves with the cursor, and stays one step ahead.
  printf(      
         "for %s\n"
         "   mat %s\n"
         "      ting %s\n"
         "           string %s\n"
         "                     addition %s\n"!,  ← still the same comma...
         param1,
         param2,
         param3,
         param4);

Step 3:

Move to the location of the next desired change.
  printf(      
         "for %s\n"
         "   mat %s\n"
         "      ting %s\n"
         "           string %s\n"
         "                     addition %s\n",
         param1,
         param2,
         param3,
         param4!);    ← but can we insert without deleting?

Step 4:

Once again, the close bracket stays one step ahead of the cursor, so just type "comma newline tab param5":
  printf(      
         "for %s\n"
         "   mat %s\n"
         "      ting %s\n"
         "           string %s\n"
         "                     addition %s\n",
         param1,
         param2,
         param3,
         param4,
         param5!);    ← no text was wasted...

It's easy enough that I edited the examples in the Netscape text editor without deleting anything.

Aren't you glad you don't use vi?

Log in or register to write something here or to contact authors.