Overview

We will write some C functions that calculate the grand totals as well as the ending balances for raw and cooked transactions. In addition to calculating the grand totals, we need to calculate the totals for each category for display in the pie charts. All of these calculations will be performed in a single C file and compiled down to a single Wasm file that will be instantiated when the application loads. C can be a little daunting for the uninitiated, so our code will be sacrificing some efficiency for the sake of clarity. I'd like to take a moment to apologize to the C/C++ programmers reading this book; you're not going to like what you C.

In order to perform calculations dynamically, we need to allocate and deallocate memory as transactions are added and deleted. To accomplish this, we'll use a doubly linked list. A doubly linked list is a data structure that allows us to remove items or nodes inside a list and add and edit nodes as needed. Nodes are added using malloc() and removed using free(), both of which are provided by the memory.wasm module you downloaded in the previous section.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset