I have been told that C++ compilers are not available for all platforms
and for many platforms they only support a basic subset of C++ features
(like just inheritance/overloading etc...). That this is especially
true for embedded platforms. Thus I am advised to use C.
You have been advised upon impossible odds. That is to say,
it's true that C++ is not available for all platforms.
However, that is meaningless because it is also true that no
language is available for all platforms. IOWs, the advise has been
provided w/o a context, at least as you have mentioned it.
W.r.t a basic subset of C++ .. especially for embedded platforms,
you are probably referring to so-called EC++ (Embedded C++).
Yes, there is such a subset defined by an industry consortium group.
Also, some compilers, for instance, Comeau C++, support a mode to
support such a dialect, however, there is generally no such
requirment that that dialect be used on using C++ for applications
intended for embedded systems.
Now, the comments may have been that C is available for more
platforms than C++, and I believe that is a fact. But that in and
of itself should not preclude one for the other.
I want my code to be usable on as wide variety of platforms as
possible.
But how possible? IOWs, you partially get to define how
far the net is cast. There are various multi-platform compilers
(gcc, Comeau, etc). Also, of this possiblity you do not mention
embedded platforms, so it is unclear if that is a hypothetical
concern or an actual concern of yours.
But I dont have much platform experience beyond coding on
windows and linux, and havnt ever tried any compiler beyond
GCC/MSVC/Borland. So I dont really know the current state of affairs.
That's a quantifiable starting point, but probably you need to define
your ending point better than "all platforms", as that is probably
unrealistic, unachievable, etc. even in the long term. Even saying
"all popular platforms" would need to be tamed.
I notice that many (almost all?) open source projects are in C, even
the new ones. Is it just because of personal choice or is it a decision
made for portability?
Could be for many reasons. However, if many == almost all, I could not
imagine that's true though.
I am a hard-core C++ developer totally in love with the language and
all of its (relatively) new features, it will be hard for me to do
non-object-oriented programming and write good code without using
templates/exceptions etc... I have done C coding too and it wont be
technically hard for me, but I don't want to shift to C unless it is a
really highly recommended option.
You probably need to say more. For instance, how deep is your
C++ investment? You being in love with C++ may be different than
your firm having already spend millions on the project in COBOL.
And so on.
What would you choose in such a situation? If I do choose C++, how much
will it really impact the usability of my code.
C++, and applications, is popular and available on many platforms.
For a sampling see
http://public.research.att.com/~bs/applications.html
ps, I am considering another option (which probably will get tossed out
of window by some of you
. Maybe I can just code it all in C++ the
way I want and port it to C when (and if) need arises.
That has at least two problems. The first is that the "porting"
effort is non-trivial for even most small applications.
The second is that the "port" may look different depending
upon the features of each respective language.
I am hoping that
by the time need arises, the compilers would have improved.
Improved in which ways? What is the limitation you are considering?
Another thought (rather a wish ;-), are there any good/reliable
translating compilers, which can translate my template and exception
heavy C++ code to C without hurting code's run-time efficiency too
much? Google gave me this disappointment:
http://en.wikipedia.org/wiki/Cfront
Comeau C++ can, although exceptions take a hit.
However, it is not clear how this helps your situation?