C++ Is to C as Lung Cancer Is to Lung 213 But you can’t tell where function boundaries are without parsing the program, and you can’t parse the program without running it through the preprocessor, and once you have done that, all occurrences of min have been removed! So you’re stuck with running grep. There are other problems with using the preprocessor for open-cod- ing. In the min macro just displayed, for instance, you will notice a number of apparently redundant parentheses. In fact, these parenthe- ses must all be provided, or else when the min macro is expanded within another expression, the result may not parse as intended. (Actually, they aren’t all necessary -- which ones may be omitted, and why, is left as an exercise for the reader.) But the nastiest problem with this min macro is that although a call to it looks like a function call, it doesn’t behave like a function call. Consider: a = min(b++, c) By textual substitution, this will be expanded to: a = ((b++) (c) ? (b++) : (c)) So if ‘b’ is less than ‘c’, ‘b’ will get incremented twice rather than once, and the value returned will be the original value of ‘b’ plus one. If min were a function, on the other hand, ‘b’ would get incremented only once, and the returned value would be the original value of ‘b’. C++ Is to C as Lung Cancer Is to Lung “If C gives you enough rope to hang yourself, then C++ gives you enough rope to bind and gag your neighborhood, rig the sails on a small ship, and still have enough rope to hang yourself from the yardarm” —Anonymous
214 C++ Sadly, though, it’s probably in the best interest of every computer scientist and serious programmer to learn C++. It’s quickly becoming a line item on resumes. Over the past few years, we’ve known many programmers who know how to program in C++, who can even write reasonably good pro- grams in the language… …but they hate it.
Previous Page Next Page