CBFalconer wrote:
This can lead to unexpected and baffling errors, especially in C. My classic example is:
char * revstring(char *s) { /* whatever, to reverse string in place, and return s */ }
....
char thestring[] = "whatever";
printf(""%s" "%s"\n", thestring, revstring(thestring));
which should print out:
"revetahw" "revetahw"
contrary to expectations. The cure is to make revstring a void function, or a procedure in Pascal. Moral: discarding function results should be awkward.
That's not primarily a problem of ignoring function results, but of (a) the existence of functions with side-effects and (b) mistaking semantics (in particular, thinking of C strings as string values rather than pointers).
(a) is inherent in Pascal as well. We could discuss whether functions should have been defined as having no side-effects, but this would be an academic discussion since we won't change the basics of Pascal.
(b) is true whenever using C strings (and in some other situations). That's why I generally recommend to avoid them. But if you use them, you'll just have to remember to look at semantics more carefully (which not every C programmer does which leads to strange errors, sure ...).
Frank