changeset 19476:8ee14c64ab5f

Document Matlab incompatibility in printf functions and bare '%' char (bug #42345). * io.txi: Document Matlab incompatibility in printf functions and bare '%' char.
author Rik <rik@octave.org>
date Tue, 30 Dec 2014 08:31:51 -0800
parents 93fbdbcb3349
children 0f79fa9b3a8c
files doc/interpreter/io.txi
diffstat 1 files changed, 17 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/doc/interpreter/io.txi	Mon Dec 29 23:05:25 2014 -0500
+++ b/doc/interpreter/io.txi	Tue Dec 30 08:31:51 2014 -0800
@@ -616,10 +616,23 @@
 @end table
 
 If the syntax of a conversion specification is invalid, unpredictable
-things will happen, so don't do this.  If there aren't enough function
-arguments provided to supply values for all the conversion
-specifications in the template string, or if the arguments are not of
-the correct types, the results are unpredictable.  If you supply more
+things will happen, so don't do this.  In particular, @sc{matlab} allows
+a bare percentage sign @samp{%} with no subsequent conversion character.
+Octave will emit an error and stop if it sees such code.  When the string
+variable to be processed cannot be guaranteed to be free of potential format
+codes it is better to use the two argument form of any of the @code{printf}
+functions and set the format string to @code{%s}.
+
+@example
+@group
+printf (strvar);        # Unsafe if strvar contains format codes
+printf ("%s", strvar);  # Safe
+@end group
+@end example
+
+If there aren't enough function arguments provided to supply values for all
+the conversion specifications in the template string, or if the arguments are
+not of the correct types, the results are unpredictable.  If you supply more
 arguments than conversion specifications, the extra argument values are
 simply ignored; this is sometimes useful.