From 22c0c8ea9798ec79dcce647a5eb1c617457f19c7 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Sat, 14 Nov 2009 21:54:18 +0000 Subject: [PATCH] Minor change to previous commit about varargs git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@11744 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Doc/Manual/Varargs.html | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/Doc/Manual/Varargs.html b/Doc/Manual/Varargs.html index f40a1ff1f..fb34a3ad9 100644 --- a/Doc/Manual/Varargs.html +++ b/Doc/Manual/Varargs.html @@ -270,21 +270,37 @@ traceprintf(arg1, NULL);

Arguably, this approach seems to defeat the whole point of variable length arguments. However, -this actually provides enough support for many simple kinds of varargs functions to still be useful. For -instance, you could make function calls like this (in Python): +this actually provides enough support for many simple kinds of varargs functions to still be useful, however it does come with a caveat. +For instance, you could make function calls like this (in Python):

 >>> traceprintf("Hello World")
 >>> traceprintf("Hello %s. Your number is %d\n" % (name, num))
+>>> traceprintf("Your result is 90%%.")
 

Notice how string formatting is being done in Python instead of C. +The caveat is the strings passed must be safe to use in C though. +For example if name was to contain a "%" it should be double escaped in order to avoid unpredictable +behaviour:

+
+
+>>> traceprintf("Your result is 90%.\n")  # unpredictable behaviour
+>>> traceprintf("Your result is 90%%.\n") # good
+
+
+ +

+Read on for further solutions. +

+ +

13.4 Argument replacement using %varargs