W
William Hughes
Andrey said:It is more about the ability to recognize "natural" where it is indeed present.
Someone already demonstrated an example of C++ template code that shows where
this feature can be extremely useful. However, it is absolutely unnecessary to
drag C++ and templates here for that purpose, because C language already has
everything necessary to achieve the level of generality that makes that feature
useful. The example follows
typedef int T;
T foo() { ... };
T bar() { return foo(); }
T baz() { return foo(); }
In at some point in the future I might decide to change the typedef to
typedef void T;
I'll have to comb through the entire program's source code and break all such
return statements into two lines. (And repeat the whole thing again when I
decide to change it back). That is heavily UNnatural. The support for "return
void" would solve the problem in a very elegant way.
So the feature in indeed objectively natural, but unfortunately it is not even
in C99.
Changing a typedef is a *very* dangerous thing to do. Unless the
change is fairly minor (e.g. one int width to another) and/or planned
on when designing the code, it is likely to lead to disaster.
Even at the best of times it is hardly "safe".
Changing a return value from non-void to void is so likely to
cause disaster that I would never do it, unless I had designed
my code to allow this from the start (In which case I would
have to turn handsprings to allow myself to use the possible
return value safely.)
This is not a good argument for allowing void functions
to return a parameter of type void.
- William Hughes