C++ inherits from a C the idea of argument lists.
So to do this you use the ellipses 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, you code must include the header file here.
Include include c.
S, t, the i, r g here as you can see here.
So this u 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 unsafe because the compiler cannot check the that parameters that the function
will get over 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 an another function here named some integer, some integer first and after.
With the comma, after the comma operator.
We're going to page the three dots here.
And in this in this sum function, we're going to create an integer.
Integer.
Sum zero.
List here.
Arguments.
Why start here?
We're going to this takes two arguments.
The first is arguments, and we're going to last.
We're going to pass the first and integer E first.
Ensure ea here first while the EA here while e is not equal to minus one, then the sum here increment
E by one one increment side by one.
And equals to have a arguments.
Alex here.
Here.
And after that we're going to use the f, a, v, a, and.
Pass this outgoings here.
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.
This type here named arguments that Val has, the file list type here.
So this variable is initialized at the beginning of the function by calling the V a start here macro
v I start macro and the stack is restored to its previous state at the end of the function by calling
the v a 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 cut has to assume the type of the variable to provide the desired type.
V the v a x here.
V a r macro here.
As you can see here, we are macro here.
So in this example, the when the v a r is called assuming and it's assuming that the every parameter
on the stack has has type of integer here.
So once our parameter has been read out of the stack, the in this code here, we're going to call the
previous code that we write it here, see out some minus one.
And of course in line C out some.
Uh, minus one, minus six, uh, minus six, minus five, minus four, minus three, minus two and
plus the minus one.
And end line here and see out some.
And here.
Less than minus one here and this corner and line here.
So.
Here.
Firstly, we're going to.
Okay.
So here, once a parameter that has been read off the stack, the code calls V, a, and V before returning
to before returning to the sum here, as you can see here.
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 this 16 here.
So since the minus one is used to indicate at 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 earth.
The second line.
This shows the 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 market value.
So another implementation called is key that the use of macro for the end of the list and instead of
first required argument to give the kind of parameters that follow here.
So now while we're going to change, we're going to write it actually from zero to sum equals zero.
Well arcs vs 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 the while we're going to change this vile code here, the vile the count is count here.
Integer.
And here integer the v a r here.
X integer.
Here, as you can see.
Count.
Count of.
Sorry.
Can't hear.
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 follow.
Suzanne So the routine will extract this number of the integers of the stack and the sum of them here.
So this code is called when we call this this code, we're going to get this zero.
If we call this.
And then it gets -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, obviously, we got an error here.
So this is no conviction for how to handle the usually determining how many parameters have been passed
here.
So the return assumes here, the routine assumes we have the C count.
Here, and let's run it again.
There.
Here.
So the routine assumes that the every items on the stack is an integer, but there is there is no information
about is 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 color provides a parameter of different types, 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 three, ten and 2030.
So it's easy to spot the comma and the period case here at the same time.
And this has happened after trying the ten 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 v a argument, v a argument macro, it will
read the eight byte double as two byte integer values and four code produced by this compiler.
The results in a total sum of just a random number here.
So this illustrates the type on safe aspect of arguments list here.
So you cannot get the compiler to do the type five checks of the parameter path to the function here.
So if your function has different types path to it, then you have to implement some mechanism to determine
what DOS parameters are.