Review:
(nothing to review from last meeting)II-5 Functions*
In this chapter we learned why we use functions (so that we can create and use a single copy of code where we were originally using many copies). The author instructs us to create our first method before main() in our file. This is so that our compiler knows the signature of the new function and can verify that we called it correctly (that is with the expected set of parameters of the correct type.) In this case, we disagree with the author in the ordering methods by deepest called first, is not useful. Instead, we are going to "prefer" to use function prototypes (forward declarations thereof) [- so that we can group functions appearing later in our code for reasons that inform such as grouping by the type of data that the functions work with, etc.]We also learned that our toolchain vendor delivered a prebuilt and tested set of functions for us to use. They gathered related groups of these prebuilt functions into libraries and we learned that there are one or more header files associated with each library. If we want to use functions from one of these libraries we simply include the header (interface) file for the library into our code and then we can call the one or more of the methods. In this chapter we see both the stdio and the unistd libraries being used.
Next the stack (call stack) was introduced along with stack-frames, local variables (or automatically allocated variables) [Note: please review this link (stack) as it in section 3 speaks, again to what forms of information are typically placed in the stack frame -ed.]
We discussed recursion, how it looks in the stack and what it looks like in the debugger. we also noted that the typical failure to normally end recursion is a stack overflow exception... we ended this discussion with the purpose of the return statement...
The last material we covered in this chapter was the scope of variables. Local (avail. only from within the containing braces), Global available to all methods in the entire application and Static global available only to methods within the same file as the statically declared global variable.
Additional Topics
At the beginning of the chapter, as were were looking at the use of printf() in the first example, we discussed the conversion by printf of some of the constants into their printable forms. This took us to the ASCII (American Standard Code for Information Interchange) interpretation of byte values. Back in the days when ASCII was most popular there was also the EBCDIC (Extended Binary Coded Decimal Interchange Code) used by predominantly by IBM machines (and IBM Emulator Machines). However, now in modern systems, we more often find ourselves using Unicode and that ASCII is encoded with the same values in a UTF-8 form of Unicode.In order to find the ASCII tables (since our internet was not avail. during the meeting) we used the man(1) command to show the ASCII man(ual) page: ASCII(7). This also demonstrated that man pages are installed on our OS X system for us to use and we access them form the terminal using the man command!
*Challenge(Triangle)
We ended this meeting by reviewing the challenge for this section. The reader was given a statement of the algorithm and some of the code. The reader is then to implement the missing code to make it all work.We discussed that in order to do this, we can reuse the technique we used while going over the recipe (shown earlier in this chapter) that of expanding the narrative first into more detailed english sentences and then by writing the code from this new more-expanded description. As we do this, we notice which code parts that we need are already provided and which aren't. The latter is our answer for this challenge!
In our case, we found the formula for summing the inside angles of a triangle within the problem narrative. We then adjusted the formula to one we could use to solve for the 3rd angle when we already know two of them. Then we implemented this formula as the body of the function we were supposed to add.
Homework: For the next meeting, in addition to the reading assignment identified in the syllabus, also review this post and all pages on wikipedia which are directly linked from this post.
No comments:
Post a Comment