CSC161 2010F, Class 36: Multi-dimensional arrays Overview: * Multi-dimensional arrays. * Why? * Arrays of pointers vs. Arrays of arrays. * K&R example, revisited. (Reading forthcoming.) * Lab. Admin: * It's prereg time! * If you know folks in 151, you should encourage them to go on to 161. * If you have questions about going on to 207, please chat with me. * EC for tomorrow's SysAdmin Thusday extra. * EC for ISO Food Bazaar * EC for SD singing the Name Game * I'm trying to reserve most of today for lab. * There is no reading for Friday. * I hope you enjoyed yesterday's digressions. I do think that it is important that prospective computer scientists know about these "big ideas" from the discipline. * As part of PragProWriMo, I'm trying to write extended pieces on the more complicated parts of K&R and C. If you observe things that you'd like a short piece (2-4 pages) on, please let me know. * We'll use a few minutes at the start of class for the final set of questions on Exam 2. (I neglected to answer MM's late-night questions, so now is a good time.) Exam 2 * In the RPN thing, why doesn't it work when I put input on the command line? * Because it's only designed to take stuff from standard input * In Problem 4, how do you fix the stupid errors? * /usr/bin/ld: /usr/lib/crt1.o (.debug_o): Relocation 0 invalid index 12 * It's obvious. Just do what it says. * Experience suggests that the problem is using a .h or something when a .c file is called for. * But I'll look at yours individually * For the general Makefile rule, do you have any hints? * General rules use a percent sign * Use the Make book to get more details. * Learn to read. Use your Tutorial professor if you can't read. * The dollar-hat thingy is useful. * When we make the general rule, do we need to provide evidence that it works? * No. But I may check. * Do we need to send you script files? * Only if you think they're necessary. * But % stuff.utest Ooh! It worked. is not very interesting for me to read * When should we write the six P's? * Not for your unit testing procedures. * Not for procedures I've provided for you. * But for other procedures you write. * What does that leave? Figure it out yourself. * What if I write a helper for my utest? * Yes. * What about macros? * No. Macros are supposed to be obvious. Or is that confusing? * When you're writing a makefile and it has both a concrete rule and a general rule, which does it use? * I think it uses the concrete rule, but it may depend on ordering. * The gallery suggests that it works either way, whether the concrete rule falls before or after the general rule. * What is the "border" that reorder produces? Once you have ordered the elements, there must be some b such that (1) for all valid i < b, a[i] <= splitter (2) for all valid j => b, a[j] > splitter Complexities: * If there are no small elements, b will be 0. * If there are no large elements, b will be size. * In part 3, we had to write unit tests. * What is the difference between unit and systematic? * unit: You run it, and they succeed, it prints nothing. If all the tests succeed, you should have good confidence (e.g., be willing to bet your grade on this test) that the procedure is correct. * systematic: you systematically cover a wide range of possibilities. * Can I have an extension of one day? * If the first letter of your nickname matches the first letter of your last name and your name is used as a nonsense word in Shirley Ellis's "The Name Game" * Can our tests be in separate C files? * Whatever you find easiest. Multi-dimensional arrays * What are they? Arrays that contain other arrays (or things like other arrays - pointers) * How do we declare them? TYPE NAME[ROWS][COLS]; TYPE NAME[PLANES][ROWS][COLS]; TYPE *NAME[ROWS]; * How do we initialize them? int stuff[3][2] = { {1,2}, {11,12}, {821,5} }; char *stuff[3] = { "banana", "fana", "fo" }; * Why do we have them? * Arrays of strings: * Physicists like matrix multiplication * Accountants like spreadsheets * Could be a way to make databases, albeit a somewhat ugly way. What's the difference between arrays of "arrays" and arrays of "pointers" * Arrays of "arrays" have allocated space and are uniform size. * Arrays of "pointers" dont' have all the space allocated and each subarray can be a different size. * In arrays of pointers, you can swap rows. In arrays of arrays, you cannot swap rows. Lab!