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.
I am asking this question with a vested interest. I would really like
to use these features in my C programs.
Masood
Why not use a C++ compiler and voluntarily restrict yourself to the
features you want? I'm assuming you are using a system where a C++
compiler is available (not always the case of course). Yes, you get a
slightly different base language in the largely common C/C++
intersection (size of char constants, differing const semantics,
additional reserved words, etc), but once you allow for that you are
set. I wonder if anyone has compiler options that restrict which C++
features you can use, or if such is even feasible. e.g. you could set
options such as "no multiple inheritance" or "no templates" or "no
overloading" or whatever policies suit you, and have the compiler
enforce your choices. It could even be smart and not enforce them
inside system headers, if that is too painful. Just a thought. If
you like this option, discussing it in comp.lang.c++ (or a compiler
group) is the way to go...
BTW, without the OO stuff, new/delete seems useless to me. Main
feature of normal new/delete beyond allocating the memory is the use
of constructors/destructors, but you said no objects? Declaring
variables just before use is C99 feature (and fairly common extension
prior to that). Not sure what you want for const. References are OK,
but, well, so are pointers which is what references are under the
hood... I'm not sure that what you are asking for is really worth
much. I like both C and C++, and don't feel a reason for C to become
more like C++. If I want to use C++ features, well, I know where to
find them.
-David