Referring to C and C++ . I wanted to know if there is anything that is possible in one of the languages and impossible in the other.
Some thoughts I had on the subject:
My first thought was the they since they both are translated to assembly, actually it should be possible to do everything we want in both languages.
But hesitating about it since C++ is a higher level language so it might not expose creating all possibilities C does and C might not expose all possible in assembly etc. As the language is higher in my opinion it is easier for the programmer but computation power is decreased. is this correct?
And in the other way around is there anything possible in C++ and not in C- I'm not referring to code efficiency and usability of the programmer (aware of polymorphism, inheritance etc.) but want to know is there's anything that is impossible in C.
Another fact to emphasize that anything possible in C is possible in C++ is using the wrapper开发者_StackOverflow中文版s of C++ for C libraries (is this considered pure C++ programing ?) (is C++ built over C? )
I'll be happy for some clarification of this subject.
Thanks!
In the sense that they're both Turing-complete languages, the answer is no.
Both C and C++ are turing complete, so you can express any abstract computation in both of them. Concrete computations (fiddling with hardware bits) is an entirely different story, so e.g. you couldn't implement what is commonly regarded as an operating system in Ruby.
Both C and C++ are sufficiently close to the metal though that you can program at hardware bit level with both of them.
Also, C++ doesn't hide anything from you that C doesn't, at least if you want to deal with all the hairy details.
Both are Turing complete so both can solve the same problems.
However C++ is almost a superset of C. Anything you can write in C can easily be written in C++ in a very similar way, usually requiring no changes at all, or occasionally requiring small changes. The reverse is not true - there are things you can write in C++ that are difficult (but not impossible) to convert directly to C. Examples are object oriented programming (polymorphism, multiple inheritance, etc...), exceptions, and so on.
You can't do this in C++ but you can in C
int* ptr = malloc(50 * sizeof(int));
C++ makes you explicitly cast the void *
And of course in C, anything to do with object orientation cannot be done. is like pounding a square peg through a round hole.
精彩评论