Hello.
Well, come on.
In this lecture, we are going to implement the variable size function and the variable size for this
function.
Now, what these functions will do is they will calculate the variable size for a variable list or an
actual variable.
This is a nice simple lecture and it is required because we will need to be calling functions like this
when we go to finish finalising our body and when we finish implementing pen dependencies for Node.
So the first thing I want you to do when you create a new file called Helper Dot C and essentially what
will go in this file is basically anything that we can't categorise.
So anything we can't categorise will go here.
It's kind of like a miscellaneous file, right?
We'll probably go through here later on and separate functions into more appropriate files.
But for now, this is a good place to put things where we're a bit unsure where they should go.
So what we're going to do, we're going to include compile sketch.
We're going to say size, tw variables, size, struct node, var node.
And this is going to be very simple.
We're just going to return data type size.
Var Node, var type.
And that is as simple as that for that variable size function.
We're now going to make variable size for list
and that's going to accept a var less node.
And we're going to include up here a certain page and we're just going to assert a few things here,
right?
So we're going to say assert that the VAR node here is a node type of variable.
And just step by here, we're going to assert that the VAR nodes here is of no type variable list because
we just want to make sure they're passing the correct nodes to the functions.
Right.
So yeah, just under here we're going to say size, tw size and of course this will be var less node
guys, not var node and we're going to set the size to zero.
And now we're just going to include
factor tot h mass in the helpers and then we're just going to say vector set, peak pointer.
Var list node.
Var list, dot list.
And we're going to set that to zero.
And then we're going to say struck node var node equals vector peak pointer.
Peter Vallis node, var list, dot list.
And we're going to say, well, var node size plus equals variable size, var node var node equals vector
peak pointer.
Var less node top.
Var list, dot list.
Okay.
And that's not a dart.
That's a, you know, the pointer point structure, pointer access.
And here we're just going to return size.
So like I said, this was a very simple lecture.
We're going to go to the Makefile and just add helper dot C in there.
So just at the top here where these objects are, we're going to we're going to just place our helper
file in there, helper todo.
Scroll down and we're going to copy and paste expression table and we're just gonna go help Perdido
Helper dot C help with that C helper dot.
And now we're just going to go make clean make.
And yeah, we can see that that works absolutely fine.
Again, ignore these warnings because it's from previous lecture where we haven't finished implementing
stuff.
So yeah, you can now see that we now have a variable size function and a variable size for list.
The final thing to do is to put them in the header file.
Copy and paste them and go to compile that h.
And we're just going to paste them in there and we're going to get rid of the bodies.
So now they're accessible.
So just put a bit of a comment here.
Gets the variable size from the given variable note
sums the variable size of all variable nodes inside the variable s node
returns the result.
So that's nice and easy.
So yeah.
What does this return a size t?
What is the size?
C.
What is the size?
T the sum of all variable node sizes in the list.
So if you have two integers in the variable list, then the size will be eight bytes because integers
for bytes on a 32 bit system.
So yeah, I hope that makes sense.
Any questions?
Let me know.