title: sub-specifiers in printf statement for width and precision
body: <pre><code>gcc (GCC) 4.1.2
  c89
  </code></pre>
  
  <p>The code:</p>
  
  <pre><code>LOG(DEBUG, "state changed [ %d ] [ %.*s ]",
      call_id,
      (int)call_info.state_text.slen,
      call_info.state_text.ptr);
  </code></pre>
  
  <p>I am just wondering about the <code>%.*s</code> according to the man pages.</p>
  
  <pre><code>*   The width is not specified in the format string, but as an additional integer value argument preceding the argument that has to be formatted.
  
  .*  The precision is not specified in the format string, but as an additional integer value argument preceding the argument that has to be formatted.
  </code></pre>
  
  <p>1) I am just wondering what is the difference between the width and the precision in the above printf statement.</p>
  
  <p>2) The second argument is an integer that will be the length of the string to print out. However, all strings should be nul terminated so how would you get the length of the string in the first place?</p>
  
  <p>3) Is there any reason you can't do the following instead?</p>
  
  <pre><code>LOG(DEBUG, "state changed [ %d ] [ %s ]",
      call_id,
      call_info.state_text.ptr);
  </code></pre>
  
  <p>4) What is the real purpose of using the <code>*</code> and <code>.*</code> sub-specifiers?</p>