Fri 09 Aug 2013 09:16:14 AM UTC, original submission:
Consider:
For me, this is inconsistent behaviour, I would expect the last command to give empty output. It seems that this is connect to the feature of being able to output matrices that "are not exact multiples of the number of conversions in the format template":
Without looking into the code, I cannot imagine the logic leading to these results, for me the most obvious implementation would be to integer-divide the number of supplied elements by the number of conversions in the output string, call C's printf accordingly and special-case the remaining elements (by cutting the output string and pass it once more to C's printf). This would give my expected behaviour. By the way, what does MATLAB do?
At the very least, the observed behaviour is a documentation bug. In 14.2.5 it says "If more than one value is to be printed in a single call, the output functions do not return to the beginning of the format template when moving on from one value to the next. This can lead to confusing output if the number of elements in the matrices are not exact multiples of the number of conversions in the format template." But here it is not more than one value that is to be printed, and also the number of elements is an exact (should say: integer) multiple of the number of output conversions.
Going a step further, I would find an added feature useful: add m and v as type modifier characters, which in the hitherto syntax are being ignored. The output should be:
Initial and trailing spaces/newlines would be left to debate, but I would keep them at a minimum, as the user can supply them in the format string. This could be implemented rather easily by a pass over the output conversion string looking for v or d in a conversion and generating a new string, substituting a %v by the corresponding sequence of %**, given by length(corresponding argument)). Obviously, mixing a %d with a %vd in a single call with both vector arguments would give an awkward situation.
|