gcc (GCC) 4.1.2
c89
The code:
LOG(DEBUG, "state changed [ %d ] [ %.*s ]",
call_id,
(int)call_info.state_text.slen,
call_info.state_text.ptr);
I am just wondering about the %.*s according to the man pages.
* 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.
1) I am just wondering what is the difference between the width and the precision in the above printf statement.
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?
3) Is there any reason you can't do the following instead?
LOG(DEBUG, "state changed [ %d ] [ %s ]",
call_id,
call_info.state_text.ptr);
4) What is the real purpose of using the * and .* sub-specifiers?