CSC195, Class 21: Functions in C Overview * Function basics * C functions vs. Java functions * Q and A * Lab Notes * Read Gries! * Don't leave your empties in the MathLAN * Silly story about Sam's trips. * Since it's taken so long for me to write the exam, I'm cancelling it. (You will only have two exams this semester, plus an optional final.) * Are there any questions about the pointers lab? ----------------------------------------a Functions in C What is a function? * A construct that takes in values and returns others. * A named and parameterized collection of code. What do functions look like in C? () { } You can have an empty parameter list. You can have an empty procedure body. You can have no type (in which case it defaults to "int"). You probably need a name. What do functions look like in Java? () { } Some modifiers: static public private protected final C also has some modifiers, but we'll ignore them for now. In C, it's a *really good idea* to declare functions before you use them. In Java, you don't usually declare functions separately from their use (interfaces and abstract classes provide some declaration-like capabilities). Java forces you to type things. Java allows you to throw exceptions. * Exceptions can be used to provide precondition checking * Allow the procedure to select the control flow used upon returning from the procedure. Do the short and sketchy lab. ---------------------------------------- REFLECTION * Does the compiler check the type or number of the parameters? * Does your friend splint? * Warnings do not stop our compiler from compiling. * The implicit return type of any undeclared procedure is int. * What do you expect our compiler or splint to say for gecko(1); gecko(1.1); * Explanation of extern, static, ... * Tail recursion: The only thing you do after a recursive call is return its value.