<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet type="text/css" href="http://wiki.lostsouls.org/w/skins/common/feed.css"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
	<channel>
		<title>Man varargs - Revision history</title>
		<link>http://wiki.lostsouls.org/w/index.php?title=Man_varargs&amp;action=history</link>
		<description>Revision history for this page on the wiki</description>
		<language>en</language>
		<generator>MediaWiki 1.8.2</generator>
		<lastBuildDate>Sun, 10 May 2026 10:34:27 GMT</lastBuildDate>
		<item>
			<title>Laine at 17:30, 11 June 2007</title>
			<link>http://wiki.lostsouls.org/w/index.php?title=Man_varargs&amp;diff=3938&amp;oldid=prev</link>
			<description>&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;==Description==&lt;br /&gt;
&lt;br /&gt;
A function uses &amp;quot;varargs&amp;quot;, short for &amp;quot;variable arguments&amp;quot;, if&lt;br /&gt;
it intentionally may be called with less or more arguments&lt;br /&gt;
than formally specified.&lt;br /&gt;
&lt;br /&gt;
The proper order to define a function call is:&lt;br /&gt;
&lt;br /&gt;
    [ modifier ] [ varargs ] [ return type ] function( args...)&lt;br /&gt;
&lt;br /&gt;
Any other order will result in an error.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Given a function definition like this:&lt;br /&gt;
&lt;br /&gt;
    void fun (string arg1, int arg2, int arg3)&lt;br /&gt;
&lt;br /&gt;
fun() has to be called with exactly three parameters: one&lt;br /&gt;
string and two integers.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
If the function is defined as&lt;br /&gt;
&lt;br /&gt;
    varargs void fun (string arg1, int arg2, int arg3)&lt;br /&gt;
&lt;br /&gt;
it is possible to call the function with just arg1, or arg1&lt;br /&gt;
and arg2. The remaining unspecified arguments (arg2 and arg3,&lt;br /&gt;
resp. arg3) are in these cases assumed to be 0.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
To pass more arguments than specified, the functions last&lt;br /&gt;
parameter must be defined as following:&lt;br /&gt;
&lt;br /&gt;
    void fun (string arg1, int arg2, varargs int * arg3)&lt;br /&gt;
&lt;br /&gt;
This allows fun() to be called with three or more arguments.&lt;br /&gt;
The arguments, except those assigned to the other parameters,&lt;br /&gt;
in this case arg1 and arg2, and collected into an array which&lt;br /&gt;
is then passed as arg3. For example&lt;br /&gt;
&lt;br /&gt;
    fun(&amp;quot;foo&amp;quot;, 1)       -&amp;gt; arg3 == ({ })&lt;br /&gt;
    fun(&amp;quot;foo&amp;quot;, 1, 2)    -&amp;gt; arg3 == ({ 2 })&lt;br /&gt;
    fun(&amp;quot;foo&amp;quot;, 1, 2, 3) -&amp;gt; arg3 == ({ 2, 3 })&lt;br /&gt;
&lt;br /&gt;
The type of the varargs argument has to be an array of the&lt;br /&gt;
expected type (int*, object*, string*, ...); in this case,&lt;br /&gt;
only integers are allowed. To accept arguments of any kind,&lt;br /&gt;
define the parameter as 'varargs mixed' or 'varargs mixed*'.&lt;br /&gt;
&lt;br /&gt;
To 'flatten' the received argument array in your own function&lt;br /&gt;
calls, use the efun apply(); e.g.:&lt;br /&gt;
&lt;br /&gt;
    apply(#'call_out, 1, arg3)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The two varargs variants can of course be combined:&lt;br /&gt;
&lt;br /&gt;
    varargs void fun (string arg1, int arg2, varargs int* arg3)&lt;br /&gt;
&lt;br /&gt;
defines a function which may be called with any number of&lt;br /&gt;
arguments.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==History==&lt;br /&gt;
&lt;br /&gt;
The possibility to pass more arguments than formally specified&lt;br /&gt;
was introduced in 3.2.1@132. Before, the excess arguments were&lt;br /&gt;
silently ignored.&lt;br /&gt;
&lt;br /&gt;
==See Also==&lt;br /&gt;
&lt;br /&gt;
[[man pragma|pragma(LPC)]], [[man apply|apply(E)]], [[man modifiers|modifiers(LPC)]]&lt;/div&gt;</description>
			<pubDate>Mon, 11 Jun 2007 17:30:32 GMT</pubDate>			<dc:creator>Laine</dc:creator>			<comments>http://wiki.lostsouls.org/Talk:Man_varargs</comments>		</item>
	</channel>
</rss>