02/25/2005 CISC181 9am (1) Function Prototypes: int smaller(int a, int b); // return the smaller of a and b int smallest(int a, int b, int c); // return the smallest of a, b, c (2) Function calls: int main (void) { int x, y, z; cout << "Enter three integer values (for x, y, z):" cin >> x >> y >> z; cout << "x=" << x << " y=" << y << " z=" << z << endl; cout << "The smaller of x and y is: " << smaller(x,y) << endl; cout << "The smaller of y and z is: " << smaller(y,z) << endl; cout << "The smallest of x, y, z is: " << smallest(x, y, z) << endl; return 0; } function prototype for main: int main(void); Distinguish between * function call, function prototype, and function definition * actual parameters and formal parameters Can you write the min function without using an "if" test? Write the smallest function (minimum of three) in at least two different ways. Side note: When "compiling" there are actually three separate steps: (1) pre-processing: #includes, #defines, etc and stripping out comments (2) compiling (the actual compiling, parsing and generating code) (3) linking Sometimes we use the word "compile" as a kind of shorthand to mean all three steps, but actually only step 2 is _really_ "compiling". Compiling itself is in two steps: parsing and generating machine code. Parsing refers to "making sense of your C++ code".. recognizing whether the syntax is correct, and separating your code into the various kinds of statments: assignments statments, for loops, if tests, etc... If you misspell a function name, the error you get comes from the linking step: If my function definition for "smallest" is mispelled as "smallist", I get this error: > make demoSmaller CC -o demoSmaller demoSmaller.cc Undefined first referenced symbol in file int smallest(int,int,int) demoSmaller.o ld: fatal: Symbol referencing errors. No output written to demoSmaller *** Error code 1 make: Fatal error: Command failed for... The "linker" is looking for a function definition for "smallest" because there is a function call to "smallest". If my function definition is for "smallist", the linking can't link the two together, and I get an error. Remaining notes moved to 02.28...