No, it is not. At least for now, C++ is not a true superset of C, and neither are C++ programs compiled to C programs (even though the first C++ compiler actually did that).Originally Posted by esbo
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)
Well C produces assembler code as does C++ at the end of the day.
Anything in C++ can be inplemented in C, it might take a few more lines, and C++ will
do some of the work and 'syntax checking'.
I certaintly C++ *could be* C 'under the bonnet'. Yes once you have your first C++
compiler written you can write more complilers in C++. It's not likely you would write it
from assembler anyway.
I think my program actually use a lot of C++ concepts, but I had to implement them in C.
A window might be a class for example. I had different types, fixed size, display only etc..
but they were all based upon one multipurpose window, with usually functionality taken away. Of course I have to do the checking if I am going to modify a display only window
not the compiler. I just don't try to modify it, that's all.
Some of it is actualy like Basic too. For example you can add strings I believe eg, S1+S2+S3 which is basically a strcat and a strcpy.
I think you're putting the focus on the wrong element (how C++ is compiled) rather than accepting that C programs are treated differently by C++ compilers. Use a C99 feature, and compiled as C++, your program could fail to compile. Even if you don't use C99 stuff (or by some miracle C99 stuff is proffered by your C++ compiler vendor), you have to wrestle with C++'s type system to get it compilable. You can't even do
p = malloc( size );
without a complaint.
In this case, it would be more important to consider that C programs, if they are not already valid C++ programs, can be modified to become valid C++ programs, since behzad_shabani intends to write a C++ program but you have a C program that does something similiar.Originally Posted by esbo
However, I do not see how this makes C++ "really C 'under the bonnet'".
It may then be better to give behzad_shabani ideas on the design rather than the implementation of the program.Originally Posted by esbo
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)
I think the main point of comparison is that C++ is a generic object oriented language, whereas C is imperative/procedural. As a result of this the process of designing programs in these two languages is drastically different.
Now sure, you can write procedural programs in C++, and you can contort C into supporting object oriented and generic programming, but that not how people generally use the languages.
It is too clear and so it is hard to see.
A dunce once searched for fire with a lighted lantern.
Had he known what fire was,
He could have cooked his rice much sooner.
A few compilers still compile C++ to C. (The version of Comeau I have does this. An embedded compiler, which doesn't support templates, I use does this.)At least for now, C++ is not a true superset of C, and neither are C++ programs compiled to C programs (even though the first C++ compiler actually did that).
If you don't consider static polymorphism in all its glory then you are only comparing a subset of C++ to C.Anything in C++ can be inplemented in C, it might take a few more lines, and C++ will do some of the work and 'syntax checking'.
The C macro processor simply isn't capable of all the same feats as templates. (As the C++ template mechanism isn't capable of all the same feats as macros.)
Your "can be implemented in C" may as well be "can be implemented in $(language)".
Your "few more lines" may as well be "infinitely many".
For all the work you would have to perform manually your "C++ is really C 'under the bonnet'" may as well be "C++ is really assembler 'under the bonnet'".
So while the statement may be true, it is meaningless.
Soma
The only template feat I can think of than can't be done with macro's is recursive templates.
You probably need to explicitly declare every instance and do away with type safety. And debugging would be virtually impossible. But In principle I submit it could be done.
Not that anyone should every try to do such a thing.
It is too clear and so it is hard to see.
A dunce once searched for fire with a lighted lantern.
Had he known what fire was,
He could have cooked his rice much sooner.
I just had the idea yesterday of porting std::vector to C. At first I thought that you'd simply need to pass the vector as a parameter rather than it being the this pointer. But there's WAY more to it than that. "A few more lines" just wont cut it. You've got to also provide to the vector a function that performs each of construction, copy-construction, copy-assignment, destruction. You've got to give it the size of the object contained, and get the type in there somehow too, probably via macros. The syntax will look awful due to no operator overloading, and overall, nobody is going to want to use it.
It'd be like saying that you could clean a large mansion's floor with a toothbrush. Well no actually, you can't. First it'd take more than one toothbrush, and second, before you get half of it done, the other half has gotten dirty again.
C really cannot do what C++ can do. Therefore C++ is much much more than C.
My homepage
Advice: Take only as directed - If symptoms persist, please see your debugger
Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"
To be honest with you C++ comes across to me as a lot of mumbo jumbo and waffle that I don't need to write a program. There is nothing there I need nor want.
Are you really that clueless?To be honest with you C++ comes across to me as a lot of mumbo jumbo and waffle that I don't need to write a program. There is nothing there I need nor want.
O_oThe only template feat I can think of than can't be done with macro's is recursive templates.
This rules out recursive templates, mutually recursive templates, nested templates, and determinism through template expansion.
So... yea... saying that macros are capable of everything templates can do except what they can't do isn't particularly useful.
O_oTo be honest with you C++ comes across to me as a lot of mumbo jumbo and waffle that I don't need to write a program. There is nothing there I need nor want.
So? It is your problem if you want to stay with C. That doesn't mean that C++ is "C under the hood". If you didn't have this ridiculous and naive opinion you might wish to use C++.
Soma