I know that this topic may inflame the "C language Taleban", but is
there any prospect of some of the neat features of C++ getting
incorporated in C? No I am not talking out the OO stuff. I am talking
about the non-OO stuff, that seems to be handled much more elegantly in
C++, as compared to C. For example new & delete, references, consts,
declaring variables just before use etc.
Note that quite a few features have already made it back -- void,
declaring variables in the middle of code, single-line comments for
instance.
There is no point to new and delete without constructors and
destructors, and to have those you'd need to introduce classes (and then
you'd have "C with classes", which was how C++ started out.
References are nice in some ways, but are really just syntactic sugar
round pointers, and can be even more confusing (especially when it isn't
obvious that a parameter may change).
Proper named and typed constants would indeed be useful, C's version of
const is a compiler convenience, and I can see those making it into C at
some point, but most of the other features depend on classes.
I can think of other things I'd like more. A typeof operator, for
example, and to have known-width arithmetic types build into the
language instead of via a header file (which isn't guaranteed to even
provide them). I'd really like a portable way of having enum values as
strings so that I could use strtoenum() for input and a printf
descriptor to output an enum as its named values. I'd like those in C++
as well...
I am asking this question with a vested interest. I would really like
to use these features in my C programs.
Why not use C++ instead, if that's what you like? That's what I do, I
use C++ for things where I want high-level features and I use C for
portability (adding C++ features to C won't make them portable, we're
over 5 years after the last C standard came out and I still can't safely
assume that any of the features introduced are portable (there seems to
be possibly one compiler and library which is fully C99 compliant) and
some systems don't even fully implement the standard from 10 years
before that).
Chris C