Minor change to previous commit about varargs
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@11744 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
parent
e0dd20350f
commit
22c0c8ea97
1 changed files with 18 additions and 2 deletions
|
|
@ -270,21 +270,37 @@ traceprintf(arg1, NULL);
|
||||||
|
|
||||||
<p>
|
<p>
|
||||||
Arguably, this approach seems to defeat the whole point of variable length arguments. However,
|
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
|
this actually provides enough support for many simple kinds of varargs functions to still be useful, however it does come with a caveat.
|
||||||
instance, you could make function calls like this (in Python):
|
For instance, you could make function calls like this (in Python):
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<div class="targetlang">
|
<div class="targetlang">
|
||||||
<pre>
|
<pre>
|
||||||
>>> traceprintf("Hello World")
|
>>> traceprintf("Hello World")
|
||||||
>>> traceprintf("Hello %s. Your number is %d\n" % (name, num))
|
>>> traceprintf("Hello %s. Your number is %d\n" % (name, num))
|
||||||
|
>>> traceprintf("Your result is 90%%.")
|
||||||
</pre>
|
</pre>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<p>
|
<p>
|
||||||
Notice how string formatting is being done in Python instead of C.
|
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:
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
|
<div class="targetlang">
|
||||||
|
<pre>
|
||||||
|
>>> traceprintf("Your result is 90%.\n") # unpredictable behaviour
|
||||||
|
>>> traceprintf("Your result is 90%%.\n") # good
|
||||||
|
</pre>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
Read on for further solutions.
|
||||||
|
</p>
|
||||||
|
|
||||||
|
|
||||||
<H2><a name="Varargs_nn5"></a>13.4 Argument replacement using %varargs</H2>
|
<H2><a name="Varargs_nn5"></a>13.4 Argument replacement using %varargs</H2>
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue