Cplusplus inherits from a C the idea of argument list.
So to do this you use the ellipsis syntax like this here.
Three dots.
So as the last parameter to indicate that the color can provide zero or more parameters.
So the compiler will check how the function is called and will allocate space on the stack for these
extra parameters.
So to access the extra parameters, your code must include the header file here include include zstd
i g here as you can see here.
So this your code must include the uh, this header file which has macros that you can use to extract
the extra parameters of the stack.
So this is inherently type unsafe because the compiler cannot check that that parameters that the function
will get of the stack at runtime will be the same type as the parameters put on the stack by the calling
code.
For example, let's make another function here named some integer, some integer first and after with
the comma after the comma.
Operator We're going to paste the three dots here.
And in this in this, some function, we're going to create an integer.
Integer sum zero.
Var list here arguments.
Verse start here.
We're going to this takes two arguments.
The first is arguments and we're going to last here.
We're going to pass the first and integer is first.
Enter here first, while the E here, while E is not equal to minus one.
Then the sum here increment a by one here one increment by one.
And equals to f a arguments args here.
Here.
And after that, we're going to use the VA.
VA and.
Pass these arguments here and return the sum lastly here.
So the definition of the function must have at least one parameter so that the macros work here.
In this case, the parameter is called the first, and it's important that your code leaves this stack
in a consistent state.
And this is carried out using a variable named Val type here named arguments that Val has the list type
here.
So this variable is initialized at the beginning of the function by calling the vastart here macro via
start macro and the stack is restored to its previous state at the end of the function by calling the
var and macro here.
So the code in this function simply iterates through the argument list and maintains a sum and the loop
here finishes when the parameter has the value of minus one and there are no macros, there are no macros
to give an indication of the type of the parameter on the stack.
So your code has to assume the type of the variable to provide the desired type with the var args here.
Var arg macro here.
As you can see here we are macro here.
So in this example the vendor var arg is called assuming.
Then the A is assuming that the every parameter on the stack has has type of integer here.
So once our parameters has been read of the stack, the in this code here, we're going to call the
previous code that we've write it here C out some minus one.
And of course end line.
See out some.
Uh, minus one, minus six, minus six, minus five, minus four, minus three, minus two and less
than minus one.
And end line here and see out some.
And here.
And lastly minus one here.
And this gonna end line here so.
Here.
Firstly, we're going to.
Okay.
So here, once parameters have been has been read off the stack.
The code calls var and rear before returning to.
Before returning to the sum here, as you can see here.
Uh, so the function can be called like this.
In this case, we're going to get the zero.
And in this case, we're going to get the -12.
And in this case, we're going to get a 16 here.
So since the minus one is used to indicate that the end of the list, it means that the sum of zero
number of parameters.
So you have to pass at least one parameters, as you can see here.
So.
And that is the minus one here.
In addition, the second line shows the here's the second line.
This shows the, um, the second line shows that you have a problem if you are passing a list of negative
numbers here.
So in this case, the minus one cannot be a parameter here.
So the problem could be addressed in this implementation by choosing another marker value.
So another implementation could skip that the use of marker for the end of the list and instead of first
required argument to give the count of parameters that follow here.
So now while we're going to change, we're going to write it actually from zero to some equals zero.
Var list args v v a start.
We're going to first pass the.
Arguments.
And here we're going to change this name to count and count here.
And while we're going to change this while code here, the while the count is count here.
Integer.
And here integer the var args here.
Integer.
Here, as you can see.
Count.
Oh, sorry.
Count here.
So and lastly, the sum of E here.
And after that, we're going to firstly end the arguments here.
Arguments and then return the sum.
Return the sum here.
So this time.
Here this time.
The first value here.
The first value is the number of arguments that follows.
And so the routine will extract this number of the integers of the stack and sum them here.
So this code is called when we call this this code, we're going to get the zero if we call this.
And then I get -21.
And if we call this, we're going to get the 60 here.
So let's make it run.
And as you can see here, oops, we got an error here.
So this is no convention for how to handle the determining how many parameters have been passed here.
So the return assumes here, the routine assumes we have to see count.
Okay.
Here and let's run it again.
Here.
So the routine assumes that the ever items on the stack is an integer.
But there is no information about this in the prototype of the function here.
So the compiler cannot do type checking on the parameters actually used to the call function here.
If the caller provides a parameter of different type, the wrong number of bytes should be read off
the stack here.
So for example, the sum.
And, uh, like this, for example.
See out some.
Here.
310 dot and 2030.
So it's easy to press both the comma and period keys here at the same time.
And this has happened after trying the temp parameter.
So the period means that the ten here, this means here ten is a double and this compiler puts a double
value on the stack here.
So in this case, the first is integer and double integer integer here, integer integer here.
So.
The compiler is going to put a double value on the stack.
So when the function reads values of the stack with the var argument.
Var argument macro it will read the eight bytes double as two byte integer values and for code produced
by this compiler, the results in a total sum of just a random number here.
So this illustrates the type unsafe aspect of arguments list here.
So you cannot get the compiler to do the type checks of the parameter passed to the function here.
So if your function has different types passed to it, then you have to implement some mechanism to
determine what those parameters are.